nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: clouditor/clouditor
Pull request #1024 (2023-03-21 18:18:29)

Adding nil check for  context to `AllowedCloudServices` of `AuthorizationStrategyJWT`
The JWT authorization strategy was missing a nil check.


Patch:
diff --git a/service/authz.go b/service/authz.go
index 95ca1a86..6bcbd261 100644
--- a/service/authz.go
+++ b/service/authz.go
@@ -93,6 +93,12 @@ func (a *AuthorizationStrategyJWT) AllowedCloudServices(ctx context.Context) (al
 		s      string
 	)
 
+	// Check, if the context is nil
+	if ctx == nil {
+		log.Debugf("Retrieving allowed cloud services failed because of an empty context")
+		return false, nil
+	}
+
 	// Retrieve the raw token from the context
 	token, err = grpc_auth.AuthFromMD(ctx, "bearer")
 	if err != nil {


Test patch:
diff --git a/service/authz_test.go b/service/authz_test.go
index f8fe6552..83bff8bb 100644
--- a/service/authz_test.go
+++ b/service/authz_test.go
@@ -286,6 +286,13 @@ func TestAuthorizationStrategyJWT_AllowedCloudServices(t *testing.T) {
 			wantAll:  false,
 			wantList: nil,
 		},
+		{
+			name:     "nil context",
+			fields:   fields{},
+			args:     args{ctx: nil},
+			wantAll:  false,
+			wantList: nil,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {