@@ -212,55 +212,55 @@ func (ms *MfaSuite) TestActivateApiKey() {
212212 localStorage , err := NewStorage (awsConfig )
213213 must (err )
214214
215- key1 := ApiKey {Key : "key1" }
215+ key1 := ApiKey {Key : "key1" , Email : "1" + exampleEmail , CreatedAt : 1744799133000 }
216216 must (localStorage .Store (envConfig .ApiKeyTable , & key1 ))
217- key2 := ApiKey {Key : "key2" , ActivatedAt : 1744799134000 }
217+ key2 := ApiKey {Key : "key2" , Email : "2" + exampleEmail , CreatedAt : 1744799133000 , ActivatedAt : 1744799134000 }
218218 must (localStorage .Store (envConfig .ApiKeyTable , & key2 ))
219- key3 := ApiKey {Key : "key3" }
219+ key3 := ApiKey {Key : "key3" , Email : "3" + exampleEmail , CreatedAt : 1744799133000 }
220220 must (localStorage .Store (envConfig .ApiKeyTable , & key3 ))
221221
222222 tests := []struct {
223223 name string
224- body any
224+ body map [ string ] string
225225 wantStatus int
226226 wantError error
227227 }{
228228 {
229229 name : "not previously activated" ,
230- body : map [string ]any {
231- "email" : exampleEmail ,
230+ body : map [string ]string {
231+ "email" : key1 . Email ,
232232 "apiKeyValue" : key1 .Key ,
233233 },
234234 wantStatus : http .StatusOK ,
235235 },
236236 {
237237 name : "already activated" ,
238- body : map [string ]any {
239- "email" : exampleEmail ,
238+ body : map [string ]string {
239+ "email" : key2 . Email ,
240240 "apiKeyValue" : key2 .Key ,
241241 },
242242 wantStatus : http .StatusBadRequest ,
243243 wantError : ErrKeyAlreadyActivated ,
244244 },
245245 {
246246 name : "missing email" ,
247- body : map [string ]any {
247+ body : map [string ]string {
248248 "apiKeyValue" : key3 .Key ,
249249 },
250250 wantStatus : http .StatusBadRequest ,
251251 wantError : errors .New ("email is required" ),
252252 },
253253 {
254- name : "missing apiKey " ,
255- body : map [string ]any {
254+ name : "missing apiKeyValue " ,
255+ body : map [string ]string {
256256 "email" : exampleEmail ,
257257 },
258258 wantStatus : http .StatusBadRequest ,
259259 wantError : errors .New ("apiKeyValue is required" ),
260260 },
261261 {
262262 name : "key not found" ,
263- body : map [string ]any {
263+ body : map [string ]string {
264264 "email" : exampleEmail ,
265265 "apiKeyValue" : "not a key" ,
266266 },
@@ -285,10 +285,18 @@ func (ms *MfaSuite) TestActivateApiKey() {
285285 ms .Equal (http .StatusOK , res .Status , fmt .Sprintf ("ActivateApiKey response: %s" , res .Body ))
286286
287287 var response struct {
288- ApiSecret string `json:"apiSecret"`
288+ Email string `json:"email"`
289+ ApiKeyValue string `json:"apiKeyValue"`
290+ ApiSecret string `json:"apiSecret"`
291+ ActivatedAt time.Time `json:"activatedAt"`
292+ CreatedAt time.Time `json:"createdAt"`
289293 }
290294 ms .NoError (json .Unmarshal (res .Body , & response ))
291- ms .Len (response .ApiSecret , 44 )
295+ ms .Regexp ("^[A-Za-z0-9+/]{43}=$" , response .ApiSecret , "apiSecret isn't correct" )
296+ ms .Equal (tt .body ["email" ], response .Email , "email isn't correct" )
297+ ms .Equal (tt .body ["apiKeyValue" ], response .ApiKeyValue , "apiKeyValue isn't correct" )
298+ ms .Equal (time .Date (2025 , 4 , 16 , 10 , 25 , 33 , 0 , time .UTC ), response .CreatedAt , "createdAt isn't correct" )
299+ ms .WithinDuration (time .Now ().UTC (), response .ActivatedAt , time .Minute , "activatedAt isn't correct" )
292300 })
293301 }
294302}
0 commit comments