veyron2: Remove Signature auth, and add Signature utilities.
Per team discussions, removed authorization checks from the
__Signature call.
Also added utilities to Copy and Clean signatures, and added
reserved methods to the interfaces returned by __Signature.
Re-enabled the signature tests, since we're now on vom2.
Change-Id: I624ded28f2dbffd62f3f16076b2de02833d3056e
MultiPart: 1/2
diff --git a/runtimes/google/ipc/glob.go b/runtimes/google/ipc/reserved.go
similarity index 95%
rename from runtimes/google/ipc/glob.go
rename to runtimes/google/ipc/reserved.go
index e274f5c..3299b6a 100644
--- a/runtimes/google/ipc/glob.go
+++ b/runtimes/google/ipc/reserved.go
@@ -16,8 +16,6 @@
"v.io/core/veyron/lib/glob"
)
-// TODO(toddw): Rename this file to "reserved.go".
-
// reservedInvoker returns a special invoker for reserved methods. This invoker
// has access to the internal dispatchers, which allows it to perform special
// handling for methods like Glob and Signature.
@@ -84,23 +82,29 @@
if disp == nil {
return nil, verror.NoExistf("ipc: no dispatcher for %q.%s", ctx.Suffix(), ctx.Method())
}
- obj, auth, err := disp.Lookup(ctx.Suffix())
+ obj, _, err := disp.Lookup(ctx.Suffix())
switch {
case err != nil:
return nil, err
case obj == nil:
return nil, verror.NoExistf("ipc: no invoker for %q.%s", ctx.Suffix(), ctx.Method())
}
- if verr := authorize(ctx, auth); verr != nil {
- return nil, verr
- }
sig, err := objectToInvoker(obj).Signature(ctx)
if err != nil {
return nil, err
}
- // TODO(toddw): add the signatures returned from reservedInvoker.
- // TODO(toddw): filter based on authorization.
- return sig, nil
+ // Append the reserved methods. We wait until now to add the "__" prefix to
+ // each method, so that we can use the regular ReflectInvoker.Signature logic.
+ rsig, err := r.selfInvoker.Signature(ctx)
+ if err != nil {
+ return nil, err
+ }
+ for i := range rsig {
+ for j := range rsig[i].Methods {
+ rsig[i].Methods[j].Name = "__" + rsig[i].Methods[j].Name
+ }
+ }
+ return signature.CleanInterfaces(append(sig, rsig...)), nil
}
func (r *reservedMethods) MethodSignature(ctxOrig ipc.ServerContext, method string) (signature.Method, error) {
diff --git a/runtimes/google/ipc/signature_test.go b/runtimes/google/ipc/signature_test.go
index 9f9b0b0..0d3d0d1 100644
--- a/runtimes/google/ipc/signature_test.go
+++ b/runtimes/google/ipc/signature_test.go
@@ -57,10 +57,7 @@
panic("X")
}
-// TODO(toddw): This test only works with vom2, since we need to send *vdl.Type
-// over the wire for the new Signature format. Re-enable this test when the
-// vom2 transition is done.
-func disabledTestMethodSignature(t *testing.T) {
+func TestMethodSignature(t *testing.T) {
runtime, err := rt.New()
if err != nil {
t.Fatalf("Couldn't initialize runtime: %s", err)
@@ -110,10 +107,7 @@
}
}
-// TODO(toddw): This test only works with vom2, since we need to send *vdl.Type
-// over the wire for the new Signature format. Re-enable this test when the
-// vom2 transition is done.
-func disabledTestSignature(t *testing.T) {
+func TestSignature(t *testing.T) {
runtime, err := rt.New()
if err != nil {
t.Fatalf("Couldn't initialize runtime: %s", err)
@@ -126,40 +120,47 @@
}
defer stop()
name := naming.JoinAddressName(ep, "")
-
- want := []signature.Interface{
- signature.Interface{
- Doc: "The empty interface contains methods not attached to any interface.",
- Methods: []signature.Method{
- {
- Name: "NonStreaming0",
- },
- {
- Name: "NonStreaming1",
- InArgs: []signature.Arg{{Type: vdl.StringType}},
- OutArgs: []signature.Arg{{Type: vdl.ErrorType}},
- },
- {
- Name: "Streaming0",
- InStream: &signature.Arg{Type: vdl.StringType},
- OutStream: &signature.Arg{Type: vdl.BoolType},
- },
- {
- Name: "Streaming1",
- InArgs: []signature.Arg{{Type: vdl.Int64Type}},
- OutArgs: []signature.Arg{{Type: vdl.Float64Type}, {Type: vdl.ErrorType}},
- InStream: &signature.Arg{Type: vdl.StringType},
- OutStream: &signature.Arg{Type: vdl.BoolType},
- },
- },
- },
- }
-
sig, err := reserved.Signature(runtime.NewContext(), nil, name)
if err != nil {
t.Errorf("call failed: %v", err)
}
- if got, want := sig, want; !reflect.DeepEqual(got, want) {
- t.Errorf("got %#v, want %#v", got, want)
+ if got, want := len(sig), 2; got != want {
+ t.Fatalf("got sig %#v len %d, want %d", sig, got, want)
+ }
+ // Check expected methods.
+ methods := signature.Interface{
+ Doc: "The empty interface contains methods not attached to any interface.",
+ Methods: []signature.Method{
+ {
+ Name: "NonStreaming0",
+ },
+ {
+ Name: "NonStreaming1",
+ InArgs: []signature.Arg{{Type: vdl.StringType}},
+ OutArgs: []signature.Arg{{Type: vdl.ErrorType}},
+ },
+ {
+ Name: "Streaming0",
+ InStream: &signature.Arg{Type: vdl.StringType},
+ OutStream: &signature.Arg{Type: vdl.BoolType},
+ },
+ {
+ Name: "Streaming1",
+ InArgs: []signature.Arg{{Type: vdl.Int64Type}},
+ OutArgs: []signature.Arg{{Type: vdl.Float64Type}, {Type: vdl.ErrorType}},
+ InStream: &signature.Arg{Type: vdl.StringType},
+ OutStream: &signature.Arg{Type: vdl.BoolType},
+ },
+ },
+ }
+ if got, want := sig[0], methods; !reflect.DeepEqual(got, want) {
+ t.Errorf("got sig[0] %#v, want %#v", got, want)
+ }
+ // Check reserved methods.
+ if got, want := sig[1].Name, "__Reserved"; got != want {
+ t.Errorf("got sig[1].Name %q, want %q", got, want)
+ }
+ if got, want := signature.MethodNames(sig[1:2]), []string{"__Glob", "__MethodSignature", "__Signature"}; !reflect.DeepEqual(got, want) {
+ t.Fatalf("got sig[1] methods %v, want %v", got, want)
}
}