Skip to content

Commit 4cd6ca0

Browse files
authored
fix: Add missing return in admin requests auth (#9422)
1 parent a5efcba commit 4cd6ca0

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

cmd/auth-handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func validateAdminSignature(ctx context.Context, r *http.Request, region string)
140140
reqInfo := (&logger.ReqInfo{}).AppendTags("requestHeaders", dumpRequest(r))
141141
ctx := logger.SetReqInfo(ctx, reqInfo)
142142
logger.LogIf(ctx, errors.New(getAPIError(s3Err).Description), logger.Application)
143+
return cred, nil, owner, s3Err
143144
}
144145

145146
claims, s3Err := checkClaimsFromToken(r, cred)

cmd/auth-handler_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ func TestIsReqAuthenticated(t *testing.T) {
391391
}
392392
}
393393
}
394+
394395
func 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

Comments
 (0)