I have a simple class making an HTTP POST request (to a Neo4j server, but that doesn't matter) using URLSession, and an integration test that checks that it succeeds.
Through Xcode, through the iOS simulator, I can run this test a million times - it succeeds every time.
However, when I run swift test on Ubuntu Linux (I use the docker image provided by IBM ), then I very often get that I got a 401 response.
Replicating this through cURL in the container will not work at all, so I don't think this is a problem with my container.
I added a batch dump (which I check through Charles Proxy ), where our 15 test runs, 7 test runs (and therefore 7 requests) fail. All failed requests complain about the lack of an authentication header. And from the dump, this is true, the dump does not contain an authentication header for those requests that fail. But why not? In fact, all header flags are different: a successful launch has the following headers:
POST /db/data/cypher HTTP/1.1 Host: 192.168.0.18:7474 Accept-Encoding: deflate, gzip Authorization: Basic bmVvNGo6c3RhY2swdmVyRmxvdw== Content-Type: application/json; charset=utf-8 Accept: application/json; charset=utf-8 Connection: keep-alive User-Agent: urlsessionTestPackageTests.xctest (unknown version) curl/7.35.0 Content-Length: 135
while unsuccessful has the following meanings:
POST /db/data/cypher HTTP/1.1 Host: 192.168.0.18:7474 Accept: */* Accept-Encoding: deflate, gzip Connection: keep-alive User-Agent: urlsessionTestPackageTests.xctest (unknown version) curl/7.35.0 Content-Length: 135
All results 200 have the same headings, and all results 401 have the same headings. Can you see anything in my code that should guarantee such a random request?