зеркало из https://github.com/Azure/ARO-RP.git
Merge pull request #2756 from s-fairchild/csp-errors
Fix failure to parse token errors as Cloud Errors - ARO-1577
This commit is contained in:
Коммит
18fcb858fe
|
@ -25,7 +25,7 @@ func (dv *dynamic) ValidateServicePrincipal(ctx context.Context, clientID, clien
|
|||
c := &azureclaim.AzureClaim{}
|
||||
_, _, err = p.ParseUnverified(token.OAuthToken(), c)
|
||||
if err != nil {
|
||||
return err
|
||||
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidServicePrincipalCredentials, "properties.servicePrincipalProfile", err.Error())
|
||||
}
|
||||
|
||||
for _, role := range c.Roles {
|
||||
|
|
|
@ -80,7 +80,7 @@ func TestValidateServicePrincipal(t *testing.T) {
|
|||
claims: `{ "Roles":["Application.ReadWrite.OwnedBy"] }`,
|
||||
signMethod: "fake-signing-method",
|
||||
},
|
||||
wantErr: "signing method (alg) is unavailable.",
|
||||
wantErr: "400: InvalidServicePrincipalCredentials: properties.servicePrincipalProfile: signing method (alg) is unavailable.",
|
||||
},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
@ -6,6 +6,7 @@ package clusterauthorizer
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/form3tech-oss/jwt-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -13,6 +14,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/api"
|
||||
"github.com/Azure/ARO-RP/pkg/util/aad"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclaim"
|
||||
"github.com/Azure/ARO-RP/pkg/util/azureclient"
|
||||
|
@ -71,7 +73,7 @@ func (a *azRefreshableAuthorizer) NewRefreshableAuthorizerToken(ctx context.Cont
|
|||
c := &azureclaim.AzureClaim{}
|
||||
_, _, err = p.ParseUnverified(token.OAuthToken(), c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidServicePrincipalCredentials, "properties.servicePrincipalProfile", "the provided service principal is invalid")
|
||||
}
|
||||
|
||||
return refreshable.NewAuthorizer(token), nil
|
||||
|
|
|
@ -128,7 +128,7 @@ func TestNewRefreshableAuthorizerToken(t *testing.T) {
|
|||
signMethod: "fake-signing-method",
|
||||
},
|
||||
secret: newV1CoreSecret(azureSecretName, nameSpace),
|
||||
wantErr: "signing method (alg) is unavailable.",
|
||||
wantErr: "400: InvalidServicePrincipalCredentials: properties.servicePrincipalProfile: the provided service principal is invalid",
|
||||
},
|
||||
{
|
||||
name: "pass: create new bearer authorizer token",
|
||||
|
|
|
@ -71,7 +71,7 @@ func (p *prod) populateTenantIDFromMSI(ctx context.Context) error {
|
|||
c := &azureclaim.AzureClaim{}
|
||||
_, _, err = parser.ParseUnverified(token.OAuthToken(), c)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("the provided service principal is invalid")
|
||||
}
|
||||
|
||||
p.tenantID = c.TenantID
|
||||
|
|
|
@ -205,7 +205,7 @@ func TestPopulateTenantIDFromMSI(t *testing.T) {
|
|||
OAuthToken().
|
||||
Return("invalid")
|
||||
},
|
||||
wantErr: "token contains an invalid number of segments",
|
||||
wantErr: "the provided service principal is invalid",
|
||||
},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
@ -236,7 +236,7 @@ func TestPopulateTenantIDFromMSI(t *testing.T) {
|
|||
|
||||
if err != nil && err.Error() != tt.wantErr ||
|
||||
err == nil && tt.wantErr != "" {
|
||||
t.Fatal(err)
|
||||
t.Fatalf("\n%v\n !=\n%v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
if p.tenantID != tt.wantTenantID {
|
||||
|
|
Загрузка…
Ссылка в новой задаче