syncbase: improve test blessing setup & use AllowEveryone dispatcher
Previously in tests we used server blessing "server" and
client blessing "server/client". This CL changes things so
that the server uses blessing "root/server" and the client
uses blessing "root/client".
The previous setup was flawed in the following way:
- Our Dispatcher.Lookup was returning a nil authorizer; the
RPC framework thus defaults to using a
security.DefaultAuthorizer(), and uses that authorizer to
perform an auth check on every request.
- The default authorizer implements a conservative policy,
where the client must present a blessing that extends the
server's blessing, or vice versa. In general, this is not
expected to be the case, and in particular with my JS
todos example app, the blessings I was using did not
satisfy this property, so all RPCs will failing with "no
access" errors.
- Our previous test setup satisfied the above property, so
the DefaultAuthorizer returned by the dispatcher had the
same effect as an AllowEveryone authorizer would've had,
and the tests ended up testing what they were intended to
test.
Returning an AllowEveryone authorizer from the dispatcher
seems like the right thing to do in our case, because the
authorization decision is more complicated than looking up
an ACL based on the tag for the called method. E.g. in some
cases we'll need to consult multiple ACLs, and in other
cases the method tag actually refers to an ACL on a
different object than the RPC receiver (e.g. Database.Create
consults the app's ACL).
Finally, I just want to note that before switching the
dispatcher to return an AllowEveryone authorizer, I verified
that our tests fail with the "root/client" and "root/server"
blessings, as expected.
Change-Id: Idfc895813bbae62c518b728d4d569c04e7a4f753
diff --git a/v23/syncbase/nosql/client_test.go b/v23/syncbase/nosql/client_test.go
index 38f66d2..731b689 100644
--- a/v23/syncbase/nosql/client_test.go
+++ b/v23/syncbase/nosql/client_test.go
@@ -178,17 +178,17 @@
// Tests that Table.{Set,Get,Delete}Permissions methods work as expected.
func TestTablePerms(t *testing.T) {
- clientACtx, sName, cleanup, sp, ctx := tu.SetupOrDieCustom("clientA", "server", nil)
+ ctx, clientACtx, sName, rootp, cleanup := tu.SetupOrDieCustom("clientA", "server", nil)
defer cleanup()
- clientBCtx := tu.NewClient("clientB", "server", ctx, sp)
+ clientBCtx := tu.NewCtx(ctx, rootp, "clientB")
a := tu.CreateApp(t, clientACtx, syncbase.NewService(sName), "a")
d := tu.CreateNoSQLDatabase(t, clientACtx, a, "d")
tb := tu.CreateTable(t, clientACtx, d, "tb")
// Permission objects.
- aAndB := tu.DefaultPerms("server/clientA", "server/clientB")
- aOnly := tu.DefaultPerms("server/clientA")
- bOnly := tu.DefaultPerms("server/clientB")
+ aAndB := tu.DefaultPerms("root/clientA", "root/clientB")
+ aOnly := tu.DefaultPerms("root/clientA")
+ bOnly := tu.DefaultPerms("root/clientB")
// Set initial permissions.
if err := tb.SetPermissions(clientACtx, nosql.Prefix(""), aAndB); err != nil {
@@ -516,17 +516,17 @@
// Test permission checking in Row.{Get,Put,Delete} and
// Table.{Scan, DeleteRowRange}.
func TestRowPermissions(t *testing.T) {
- clientACtx, sName, cleanup, sp, ctx := tu.SetupOrDieCustom("clientA", "server", nil)
+ ctx, clientACtx, sName, rootp, cleanup := tu.SetupOrDieCustom("clientA", "server", nil)
defer cleanup()
- clientBCtx := tu.NewClient("clientB", "server", ctx, sp)
+ clientBCtx := tu.NewCtx(ctx, rootp, "clientB")
a := tu.CreateApp(t, clientACtx, syncbase.NewService(sName), "a")
d := tu.CreateNoSQLDatabase(t, clientACtx, a, "d")
tb := tu.CreateTable(t, clientACtx, d, "tb")
// Permission objects.
- aAndB := tu.DefaultPerms("server/clientA", "server/clientB")
- aOnly := tu.DefaultPerms("server/clientA")
- bOnly := tu.DefaultPerms("server/clientB")
+ aAndB := tu.DefaultPerms("root/clientA", "root/clientB")
+ aOnly := tu.DefaultPerms("root/clientA")
+ bOnly := tu.DefaultPerms("root/clientB")
// Set initial permissions.
if err := tb.SetPermissions(clientACtx, nosql.Prefix(""), aAndB); err != nil {