addData('base'); } /** * Ensure authentication against the API works */ public function testApiAuthentication() { $uri = '/api/airports/kjfk'; // Missing auth header $this->get($uri)->assertStatus(401); // Test invalid API key $this->withHeaders(['Authorization' => 'invalidKey'])->get($uri) ->assertStatus(401); // Test upper/lower case of Authorization header, etc $this->withHeaders(self::$auth_headers)->get($uri) ->assertStatus(200) ->assertJson(['icao' => 'KJFK'], true); $this->withHeaders(['AUTHORIZATION' => 'testapikey'])->get($uri) ->assertStatus(200) ->assertJson(['icao' => 'KJFK'], true); } /** * Make sure the airport data is returned */ public function testAirportRequest() { $this->withHeaders(self::$auth_headers)->get('/api/airports/KJFK') ->assertStatus(200) ->assertJson(['icao' => 'KJFK'], true); $this->withHeaders(self::$auth_headers)->get('/api/airports/UNK') ->assertStatus(404); } }