@@ -391,6 +391,7 @@ func TestIsReqAuthenticated(t *testing.T) {
391391 }
392392 }
393393}
394+
394395func TestCheckAdminRequestAuthType (t * testing.T ) {
395396 objLayer , fsDir , err := prepareFS ()
396397 if err != nil {
@@ -425,3 +426,48 @@ func TestCheckAdminRequestAuthType(t *testing.T) {
425426 }
426427 }
427428}
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