@@ -391,6 +391,7 @@ func TestIsReqAuthenticated(t *testing.T) {
391
391
}
392
392
}
393
393
}
394
+
394
395
func TestCheckAdminRequestAuthType (t * testing.T ) {
395
396
objLayer , fsDir , err := prepareFS ()
396
397
if err != nil {
@@ -425,3 +426,48 @@ func TestCheckAdminRequestAuthType(t *testing.T) {
425
426
}
426
427
}
427
428
}
429
+
430
+ func TestValidateAdminSignature (t * testing.T ) {
431
+
432
+ ctx := context .Background ()
433
+
434
+ objLayer , fsDir , err := prepareFS ()
435
+ if err != nil {
436
+ t .Fatal (err )
437
+ }
438
+ defer os .RemoveAll (fsDir )
439
+
440
+ if err = newTestConfig (globalMinioDefaultRegion , objLayer ); err != nil {
441
+ t .Fatalf ("unable initialize config file, %s" , err )
442
+ }
443
+
444
+ creds , err := auth .CreateCredentials ("admin" , "mypassword" )
445
+ if err != nil {
446
+ t .Fatalf ("unable create credential, %s" , err )
447
+ }
448
+ globalActiveCred = creds
449
+
450
+ testCases := []struct {
451
+ AccessKey string
452
+ SecretKey string
453
+ ErrCode APIErrorCode
454
+ }{
455
+ {"" , "" , ErrInvalidAccessKeyID },
456
+ {"admin" , "" , ErrSignatureDoesNotMatch },
457
+ {"admin" , "wrongpassword" , ErrSignatureDoesNotMatch },
458
+ {"wronguser" , "mypassword" , ErrInvalidAccessKeyID },
459
+ {"" , "mypassword" , ErrInvalidAccessKeyID },
460
+ {"admin" , "mypassword" , ErrNone },
461
+ }
462
+
463
+ for i , testCase := range testCases {
464
+ req := mustNewRequest ("GET" , "http://localhost:9000/" , 0 , nil , t )
465
+ if err := signRequestV4 (req , testCase .AccessKey , testCase .SecretKey ); err != nil {
466
+ t .Fatalf ("Unable to inititalized new signed http request %s" , err )
467
+ }
468
+ _ , _ , _ , s3Error := validateAdminSignature (ctx , req , globalMinioDefaultRegion )
469
+ if s3Error != testCase .ErrCode {
470
+ t .Errorf ("Test %d: Unexpected s3error returned wanted %d, got %d" , i + 1 , testCase .ErrCode , s3Error )
471
+ }
472
+ }
473
+ }
0 commit comments