auth: rename auth.Namespace to auth.Issuer (#1710)
This commit is contained in:
@@ -158,7 +158,7 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac
|
||||
|
||||
// set the namespace header if it has not been set (e.g. on a service to service request)
|
||||
if _, ok := metadata.Get(ctx, "Micro-Namespace"); !ok {
|
||||
ctx = metadata.Set(ctx, "Micro-Namespace", aa.Options().Namespace)
|
||||
ctx = metadata.Set(ctx, "Micro-Namespace", aa.Options().Issuer)
|
||||
}
|
||||
|
||||
// check to see if we have a valid access token
|
||||
@@ -205,7 +205,7 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper {
|
||||
// Extract the namespace header
|
||||
ns, ok := metadata.Get(ctx, "Micro-Namespace")
|
||||
if !ok {
|
||||
ns = a.Options().Namespace
|
||||
ns = a.Options().Issuer
|
||||
ctx = metadata.Set(ctx, "Micro-Namespace", ns)
|
||||
}
|
||||
|
||||
|
@@ -61,7 +61,7 @@ func TestWrapper(t *testing.T) {
|
||||
type testAuth struct {
|
||||
verifyCount int
|
||||
inspectCount int
|
||||
namespace string
|
||||
issuer string
|
||||
inspectAccount *auth.Account
|
||||
verifyError error
|
||||
|
||||
@@ -79,7 +79,7 @@ func (a *testAuth) Inspect(token string) (*auth.Account, error) {
|
||||
}
|
||||
|
||||
func (a *testAuth) Options() auth.Options {
|
||||
return auth.Options{Namespace: a.namespace}
|
||||
return auth.Options{Issuer: a.issuer}
|
||||
}
|
||||
|
||||
type testRequest struct {
|
||||
@@ -171,10 +171,10 @@ func TestAuthHandler(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// If the namespace header was not set on the request, the wrapper should set it to the auths
|
||||
// own namespace
|
||||
t.Run("BlankNamespaceHeader", func(t *testing.T) {
|
||||
a := testAuth{namespace: "mynamespace"}
|
||||
// If the issuer header was not set on the request, the wrapper should set it to the auths
|
||||
// own issuer
|
||||
t.Run("BlankissuerHeader", func(t *testing.T) {
|
||||
a := testAuth{issuer: "myissuer"}
|
||||
handler := AuthHandler(func() auth.Auth {
|
||||
return &a
|
||||
})
|
||||
@@ -189,17 +189,17 @@ func TestAuthHandler(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil error but got %v", err)
|
||||
}
|
||||
if ns, _ := metadata.Get(inCtx, "Micro-Namespace"); ns != a.namespace {
|
||||
t.Errorf("Expected namespace to be set to %v but was %v", a.namespace, ns)
|
||||
if ns, _ := metadata.Get(inCtx, "Micro-Namespace"); ns != a.issuer {
|
||||
t.Errorf("Expected issuer to be set to %v but was %v", a.issuer, ns)
|
||||
}
|
||||
})
|
||||
t.Run("ValidNamespaceHeader", func(t *testing.T) {
|
||||
a := testAuth{namespace: "mynamespace"}
|
||||
t.Run("ValidissuerHeader", func(t *testing.T) {
|
||||
a := testAuth{issuer: "myissuer"}
|
||||
handler := AuthHandler(func() auth.Auth {
|
||||
return &a
|
||||
})
|
||||
|
||||
inNs := "reqnamespace"
|
||||
inNs := "reqissuer"
|
||||
inCtx := metadata.Set(context.TODO(), "Micro-Namespace", inNs)
|
||||
h := func(ctx context.Context, req server.Request, rsp interface{}) error {
|
||||
inCtx = ctx
|
||||
@@ -211,7 +211,7 @@ func TestAuthHandler(t *testing.T) {
|
||||
t.Errorf("Expected nil error but got %v", err)
|
||||
}
|
||||
if ns, _ := metadata.Get(inCtx, "Micro-Namespace"); ns != inNs {
|
||||
t.Errorf("Expected namespace to remain as %v but was set to %v", inNs, ns)
|
||||
t.Errorf("Expected issuer to remain as %v but was set to %v", inNs, ns)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -219,8 +219,8 @@ func TestAuthHandler(t *testing.T) {
|
||||
// should be forbidden
|
||||
t.Run("InvalidAccountIssuer", func(t *testing.T) {
|
||||
a := testAuth{
|
||||
namespace: "validnamespace",
|
||||
inspectAccount: &auth.Account{Issuer: "invalidnamespace"},
|
||||
issuer: "validissuer",
|
||||
inspectAccount: &auth.Account{Issuer: "invalidissuer"},
|
||||
}
|
||||
|
||||
handler := AuthHandler(func() auth.Auth {
|
||||
@@ -235,8 +235,8 @@ func TestAuthHandler(t *testing.T) {
|
||||
})
|
||||
t.Run("ValidAccountIssuer", func(t *testing.T) {
|
||||
a := testAuth{
|
||||
namespace: "validnamespace",
|
||||
inspectAccount: &auth.Account{Issuer: "validnamespace"},
|
||||
issuer: "validissuer",
|
||||
inspectAccount: &auth.Account{Issuer: "validissuer"},
|
||||
}
|
||||
|
||||
handler := AuthHandler(func() auth.Auth {
|
||||
|
Reference in New Issue
Block a user