@@ -45,6 +45,7 @@ func (suite *ServerTestSuite) SetupTest() {
4545 authenticator : authenticator ,
4646 jwtSecret : "aaa" ,
4747 tokenDurationSeconds : 60 ,
48+ apiKey : "valid" ,
4849
4950 historyStore : historyStore ,
5051 recStore : recStore ,
@@ -91,6 +92,26 @@ func (suite *ServerTestSuite) TestGetAuthTokenInvalidPassword() {
9192 assert .Equal (suite .T (), response .Code , http .StatusForbidden )
9293}
9394
95+ func (suite * ServerTestSuite ) TestApiKey () {
96+ request , _ := http .NewRequest (http .MethodGet , "/api/recs" , nil )
97+ request .Header .Add ("Authorization" , fmt .Sprintf ("ApiKey %s" , "valid" ))
98+ response := httptest .NewRecorder ()
99+
100+ suite .server .ServeHTTP (response , request )
101+
102+ assert .Equal (suite .T (), http .StatusOK , response .Code )
103+ }
104+
105+ func (suite * ServerTestSuite ) TestApiKeyInvalid () {
106+ request , _ := http .NewRequest (http .MethodGet , "/api/recs" , nil )
107+ request .Header .Add ("Authorization" , fmt .Sprintf ("ApiKey %s" , "invalid" ))
108+ response := httptest .NewRecorder ()
109+
110+ suite .server .ServeHTTP (response , request )
111+
112+ assert .Equal (suite .T (), http .StatusUnauthorized , response .Code )
113+ }
114+
94115func (suite * ServerTestSuite ) TestGetHis () {
95116 // Insert data for 2 different points with varying timestamps
96117 pointId1 := uuid .New ()
0 commit comments