Example #1
0
func createTokenForUser(user *auth.User, perm, contextType, contextValue string, c *check.C) auth.Token {
	token, err := nativeScheme.Login(map[string]string{"email": user.Email, "password": "******"})
	c.Assert(err, check.IsNil)
	role, err := permission.NewRole("provisioner-docker-"+user.Email+perm, contextType, "")
	c.Assert(err, check.IsNil)
	err = role.AddPermissions(perm)
	c.Assert(err, check.IsNil)
	err = user.AddRole(role.Name, contextValue)
	c.Assert(err, check.IsNil)
	return token
}
Example #2
0
func addSuperRole(u *auth.User) error {
	defaultRoleName := "AllowAll"
	r, err := permission.FindRole(defaultRoleName)
	if err != nil {
		r, err = permission.NewRole(defaultRoleName, string(permission.CtxGlobal), "")
		if err != nil {
			return err
		}
	}
	err = r.AddPermissions("*")
	if err != nil {
		return err
	}
	return u.AddRole(defaultRoleName, "")
}
Example #3
0
func (s *GandalfSuite) TestSync(c *check.C) {
	var buf bytes.Buffer
	conn, err := db.Conn()
	c.Assert(err, check.IsNil)
	defer conn.Close()
	defer dbtest.ClearAllCollections(conn.Apps().Database)
	var manager gandalfManager
	user1 := auth.User{Email: "*****@*****.**"}
	user2 := auth.User{Email: "*****@*****.**"}
	err = conn.Users().Insert(user1, user2)
	c.Assert(err, check.IsNil)
	role, err := permission.NewRole("deployRole", string(permission.CtxTeam), "")
	c.Assert(err, check.IsNil)
	err = role.AddPermissions("app.deploy")
	c.Assert(err, check.IsNil)
	err = user1.AddRole(role.Name, "superteam")
	c.Assert(err, check.IsNil)
	err = user2.AddRole(role.Name, "superteam")
	c.Assert(err, check.IsNil)
	err = manager.CreateUser(user1.Email)
	c.Assert(err, check.IsNil)
	team := auth.Team{Name: "superteam"}
	err = conn.Teams().Insert(team)
	c.Assert(err, check.IsNil)
	app1 := app.App{Name: "myapp", Teams: []string{team.Name}}
	app2 := app.App{Name: "yourapp", Teams: []string{team.Name}}
	app3 := app.App{Name: "hisapp", Teams: []string{team.Name}}
	err = conn.Apps().Insert(app1, app2, app3)
	c.Assert(err, check.IsNil)
	err = manager.CreateRepository(app2.Name, []string{user1.Email})
	c.Assert(err, check.IsNil)
	err = Sync(&buf)
	c.Assert(err, check.IsNil)
	c.Assert(s.server.Users(), check.DeepEquals, []string{user1.Email, user2.Email})
	expectedRepos := []gandalftest.Repository{
		{
			Name:         "yourapp",
			Users:        []string{user1.Email, user2.Email},
			ReadWriteURL: "git@localhost:yourapp.git",
			IsPublic:     true,
		},
		{
			Name:         "myapp",
			Users:        []string{user1.Email, user2.Email},
			ReadWriteURL: "git@localhost:myapp.git",
			IsPublic:     true,
		},
		{
			Name:         "hisapp",
			Users:        []string{user1.Email, user2.Email},
			ReadWriteURL: "git@localhost:hisapp.git",
			IsPublic:     true,
		},
	}
	repositories := s.server.Repositories()
	for i, repo := range repositories {
		repo.Diffs = nil
		repo.ReadOnlyURL = ""
		repositories[i] = repo
	}
	c.Assert(repositories, check.DeepEquals, expectedRepos)
	expected := `Syncing user "*****@*****.**"... already present in Gandalf
Syncing user "*****@*****.**"... OK
Syncing app "myapp"... OK
Syncing app "yourapp"... already present in Gandalf
Syncing app "hisapp"... OK
`
	c.Assert(buf.String(), check.Equals, expected)
}