@@ -210,55 +210,55 @@ func (ms *MfaSuite) TestActivateApiKey() {
210210 localStorage , err := NewStorage (awsConfig )
211211 must (err )
212212
213- key1 := ApiKey {Key : "key1" }
213+ key1 := ApiKey {Key : "key1" , Email : "1" + exampleEmail }
214214 must (localStorage .Store (envConfig .ApiKeyTable , & key1 ))
215- key2 := ApiKey {Key : "key2" , ActivatedAt : 1744799134000 }
215+ key2 := ApiKey {Key : "key2" , Email : "2" + exampleEmail , ActivatedAt : 1744799134000 }
216216 must (localStorage .Store (envConfig .ApiKeyTable , & key2 ))
217- key3 := ApiKey {Key : "key3" }
217+ key3 := ApiKey {Key : "key3" , Email : "3" + exampleEmail }
218218 must (localStorage .Store (envConfig .ApiKeyTable , & key3 ))
219219
220220 tests := []struct {
221221 name string
222- body any
222+ body map [ string ] string
223223 wantStatus int
224224 wantError error
225225 }{
226226 {
227227 name : "not previously activated" ,
228- body : map [string ]any {
229- "email" : exampleEmail ,
228+ body : map [string ]string {
229+ "email" : key1 . Email ,
230230 "apiKeyValue" : key1 .Key ,
231231 },
232232 wantStatus : http .StatusOK ,
233233 },
234234 {
235235 name : "already activated" ,
236- body : map [string ]any {
237- "email" : exampleEmail ,
236+ body : map [string ]string {
237+ "email" : key2 . Email ,
238238 "apiKeyValue" : key2 .Key ,
239239 },
240240 wantStatus : http .StatusBadRequest ,
241241 wantError : ErrKeyAlreadyActivated ,
242242 },
243243 {
244244 name : "missing email" ,
245- body : map [string ]any {
245+ body : map [string ]string {
246246 "apiKeyValue" : key3 .Key ,
247247 },
248248 wantStatus : http .StatusBadRequest ,
249249 wantError : errors .New ("email is required" ),
250250 },
251251 {
252- name : "missing apiKey " ,
253- body : map [string ]any {
252+ name : "missing apiKeyValue " ,
253+ body : map [string ]string {
254254 "email" : exampleEmail ,
255255 },
256256 wantStatus : http .StatusBadRequest ,
257257 wantError : errors .New ("apiKeyValue is required" ),
258258 },
259259 {
260260 name : "key not found" ,
261- body : map [string ]any {
261+ body : map [string ]string {
262262 "email" : exampleEmail ,
263263 "apiKeyValue" : "not a key" ,
264264 },
@@ -283,10 +283,17 @@ func (ms *MfaSuite) TestActivateApiKey() {
283283 ms .Equal (http .StatusOK , res .Status , fmt .Sprintf ("ActivateApiKey response: %s" , res .Body ))
284284
285285 var response struct {
286- ApiSecret string `json:"apiSecret"`
286+ Email string `json:"email"`
287+ ApiKeyValue string `json:"apiKeyValue"`
288+ ApiSecret string `json:"apiSecret"`
289+ ActivatedAt time.Time `json:"activatedAt"`
290+ CreatedAt time.Time `json:"createdAt"`
287291 }
288292 ms .NoError (json .Unmarshal (res .Body , & response ))
289- ms .Len (response .ApiSecret , 44 )
293+ ms .Regexp ("^[A-Za-z0-9+/]{43}=$" , response .ApiSecret , "apiSecret isn't correct" )
294+ ms .Equal (tt .body ["email" ], response .Email , "email isn't correct" )
295+ ms .Equal (tt .body ["apiKeyValue" ], response .ApiKeyValue , "apiKeyValue isn't correct" )
296+ ms .WithinDuration (time .Now ().UTC (), response .ActivatedAt , time .Minute , "activatedAt isn't correct" )
290297 })
291298 }
292299}
0 commit comments