Improve ACL testing. #6384

Merged
merged 1 commit into from Dec 5, 2016

Conversation

Projects
None yet
4 participants
Contributor

perrito666 commented Oct 5, 2016

  • Improve ACL testing on some areas that where deemed undertested.
  • Fix add-model so it support --owner when run by a user with
    addmodel permission instead of superuser.

This fixes https://bugs.launchpad.net/juju/+bug/1618966

QA Steps

  • Run unit tests
  • Bootstrap a controller
  • Add a user
  • Grant that user "addmodel" permission
  • Add another user
  • Log in as that user
  • juju add-model --owner=theseconduser amodelname
  • A new model with theseconduser as owner is created.
apiserver/controller/controller_test.go
@@ -59,7 +59,7 @@ func (s *controllerSuite) SetUpTest(c *gc.C) {
AdminTag: s.Owner,
}
- controller, err := controller.NewControllerAPI(s.State, s.resources, s.authorizer)
+ controller, err := controller.NewControllerAPI(s.State, s.resources, &s.authorizer)
@wallyworld

wallyworld Oct 10, 2016

Owner

I don't think you want this change

@perrito666

perrito666 Oct 11, 2016

Contributor

true, tx

apiserver/controller/controller_test.go
@@ -638,6 +638,15 @@ func (s *controllerSuite) modifyControllerAccess(c *gc.C, user names.UserTag, ac
return result.OneError()
}
+func (s *controllerSuite) TestAddModelCantGrant(c *gc.C) {
@wallyworld

wallyworld Oct 10, 2016

Owner

So this is testing that a model owner cannot grant add-model access to a controller?
That seems a bit narrow - the only users who can grant add-model access to a controller are users with superuser access on the controller. I'm sure there are tests somewhere that check this matrix. I am not sure the point of adding a single extra test here.

@perrito666

perrito666 Oct 11, 2016

Contributor

it actually checks that someone with addmodel cant grant permissions on a given controller, I think we had this bug earlier, that is why I added it.

apiserver/modelmanager/modelinfo_test.go
@@ -468,6 +468,15 @@ func (st *mockState) RemoveModelUser(tag names.UserTag) error {
func (st *mockState) UserAccess(tag names.UserTag, target names.Tag) (permission.UserAccess, error) {
st.MethodCall(st, "ModelUser", tag, target)
+ for _, user := range st.users {
+ if user.UserTag == tag {
@wallyworld

wallyworld Oct 10, 2016

Owner

we could save a level of indentation by inverting the if and using continue

@perrito666

perrito666 Oct 11, 2016

Contributor

fixed

apiserver/modelmanager/modelmanager.go
+ return m.getModelInfoPluggableAuth(tag, m.authCheck)
+}
+
+func (m *ModelManagerAPI) getModelInfoPluggableAuth(tag names.ModelTag,
@wallyworld

wallyworld Oct 10, 2016

Owner

I don't see what this pluggableAuth change is for. The only functional difference I can see is that we are passing in something that always return nil when called by CreateModel. Why isn't the current authCheck sufficient in that case?

@perrito666

perrito666 Oct 11, 2016

Contributor

because, touching authcheck at this point might have undetectable side effects since iirc its being used by more than one places.

@perrito666

perrito666 Oct 11, 2016

Contributor

because authcheck is a generic little thing that is used a few times and its not the purpose of this PR factor it out in favor of a modern aproach to the check so I wont change auth check and risk un-intented collateral behaviors that could be potentially untested.

@wallyworld

wallyworld Oct 12, 2016

Owner

I think my point is that the current authCheck code should be sufficient without any changes needed

@@ -42,8 +42,21 @@ import (
type modelManagerBaseSuite struct {
}
+func (s *modelManagerBaseSuite) createArgs(c *gc.C, owner names.UserTag) params.ModelCreateArgs {
@wallyworld

wallyworld Oct 10, 2016

Owner

this method doesn't need to be on a suite - it can just be a stand alone helper
it also doesn't use the c *gc.C arg

@perrito666

perrito666 Oct 11, 2016

Contributor

Fixed.

type modelManagerSuite struct {
gitjujutesting.IsolationSuite
+ modelManagerBaseSuite
@wallyworld

wallyworld Oct 10, 2016

Owner

you can't embed a new suite without adding the necessary SetUp and TearDown funcs to call into IsolationSuite and modelManagerBaseSuite

@perrito666

perrito666 Oct 11, 2016

Contributor

modelManagerBaseSuite is no longer embeded so no need to write the methods.

@@ -590,10 +603,50 @@ func (s *modelManagerSuite) TestDumpModelsDBUsers(c *gc.C) {
}
}
+func (s *modelManagerSuite) TestAddModelCanCreateModel(c *gc.C) {
@wallyworld

wallyworld Oct 10, 2016

Owner

Is there a test that users without add-model access cannot add a model? This test really belongs next to that.
We already have
TestUserCanCreateModel
TestAdminCanCreateModelForSomeoneElse
TestNonAdminCannotCreateModelForSomeoneElse

etc

These belong next to those. It may be getting to the point where a table test with {user, access, allowed} is a better approach

@@ -590,10 +603,50 @@ func (s *modelManagerSuite) TestDumpModelsDBUsers(c *gc.C) {
}
}
+func (s *modelManagerSuite) TestAddModelCanCreateModel(c *gc.C) {
+ addmodel := names.NewUserTag("addmodel@local")
@wallyworld

wallyworld Oct 10, 2016

Owner

@Local is deprecated, no need to introduce new usages of it

@perrito666

perrito666 Oct 11, 2016

Contributor

well it was writen before you deprecate it :p fixed.

@@ -590,10 +603,50 @@ func (s *modelManagerSuite) TestDumpModelsDBUsers(c *gc.C) {
}
}
+func (s *modelManagerSuite) TestAddModelCanCreateModel(c *gc.C) {
+ addmodel := names.NewUserTag("addmodel@local")
@wallyworld

wallyworld Oct 10, 2016

Owner

addModelUser would be better

@perrito666

perrito666 Oct 11, 2016

Contributor

fixed

apiserver/testing/fakeauthorizer.go
+ return false, nil
+}
+
+func nameBasedHasPermission(name string, operation permission.Access, target names.Tag) bool {
@wallyworld

wallyworld Oct 10, 2016

Owner

this really needs a comment to explain why it is needed
it seems like it would remove the need for HasWriteTag

@perrito666

perrito666 Oct 11, 2016

Contributor

yes, it will, baby steps.

Contributor

perrito666 commented Oct 13, 2016

@wallyworld ptal I added a few changes

@perrito666 perrito666 changed the base branch from master to develop Oct 14, 2016

Contributor

perrito666 commented Nov 3, 2016

!!try!!

Owner

nskaggs commented Nov 3, 2016

!!retry!!

Contributor

perrito666 commented Dec 1, 2016

$$merge$$

Contributor

jujubot commented Dec 1, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

Contributor

jujubot commented Dec 1, 2016

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/9759

Owner

nskaggs commented Dec 1, 2016

The build failed the ACL functional test. It did the following:

create a read-only user for a model and register them
change there password
logout
attempt to login again

When the test attempted to login again, it did not prompt for a password as it should as the user should no longer be logged in. That would be a problem :-)

Improve ACL testing.
* Improve ACL testing on some areas that where deemed undertested.
* Fix add-model so it support --owner when run by a user with
addmodel permission instead of superuser.
Contributor

perrito666 commented Dec 5, 2016

!!try!!

Contributor

perrito666 commented Dec 5, 2016

$$merge$$

Contributor

jujubot commented Dec 5, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit 86ab416 into juju:develop Dec 5, 2016

1 check passed

github-check-merge-juju Built PR, ran unit tests, and tested LXD deploy. Use !!.*!! to request another build. IE, !!build!!, !!retry!!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment