I have API tests in Rest Assured that is flaky for some reason.
I want to check that a media file link is correct and working. The media link goes through cdn, the audio files themselves are store in Google Cloud Storage. I'm checking that the response code is 200 for that URL.
fun getStatusCodeForRandomUrl(): Pair<Int, String> {
val randomUrl = getRandomMediaUrlFromServer()
val statusCode = `when`()
.head(randomUrl)
.statusCode
val result = Pair(statusCode, randomUrl)
assertEquals(200, result.first, "Non 200 code for: ${result.second} ")
}
The problem is that almost for half of the links I'm getting code is 403 (and for one of the URL it's even 404) in Rest Assured. But I'm getting correct 200 in Postman for all URLs. Also, it's opening correct media with these links in a browser. All media links are public and not requered auth.
The "broken" links are always the same ones. And they all are opening fine in the browser or Postman.
I've made work-around: I'm trying several times to links for 200 then for 403 codes, but that doesn't look like the way to do it.
Here is an example of the URL which failed my test case:
https://cdn.vyng.me/audio/ringtones/gagan/Channa%20ve%20Channa.mp3?GoogleAccessId=content-manager%40vyng-1148.iam.gserviceaccount.com&Expires=1913108526&Signature=RpAP%2FqqzTtEJ9JD7OMRG1QUXPYDK3CbJwMVuX%2FmmuTqPnANM77fJOPFzy5kKIguB%2BAiRemfa2Z9N0K5UhH65UjS1ov7hRNLzu9uywb91unVCPKLP8tWo5ZrabmwVHuJsjOrIPTC57bLCC00i5fcnrYirG63BuzbJDNyvzCANQUvUY0EbNUbjX8p6hXZsKkllda7RKSl3JM4WNnlPtIaI0BygGyANsjomd9FsoPgKWZseR0hl45Uw9bCNgOyxW15payndp1fRVAOax0L4AWpX7gwDhg%2F%2F5ChhYXkCHZG5g0tAKME7ihH%2FiFSv98fPA9gidIuvdIQlT9eaJNxDiqk4Cw%3D%3D
==> expected: <200> but was: <404>
These tests are flaky. Maybe somebody faced the same issue and found a solution? Why I'm getting OK 200 code for all URLs in Postman, but for half of them 403/404 in Rest Assured?