本文整理汇总了Golang中github.com/tsuru/gandalf/user.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestAddKeyShouldNotAcceptRepeatedKeysForDifferentUsers
func (s *S) TestAddKeyShouldNotAcceptRepeatedKeysForDifferentUsers(c *gocheck.C) {
usr, err := user.New("Frodo", map[string]string{"keyname": rawKey})
c.Assert(err, gocheck.IsNil)
defer user.Remove(usr.Name)
usr2, err := user.New("tempo", nil)
c.Assert(err, gocheck.IsNil)
defer user.Remove(usr2.Name)
b := strings.NewReader(fmt.Sprintf(`{"keyname": %q}`, rawKey))
recorder, request := post(fmt.Sprintf("/user/%s/key?:name=%s", usr2.Name, usr2.Name), b, c)
AddKey(recorder, request)
got := readBody(recorder.Body, c)
expected := "Key already exists.\n"
c.Assert(got, gocheck.Equals, expected)
c.Assert(recorder.Code, gocheck.Equals, http.StatusConflict)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:15,代码来源:handler_test.go
示例2: TestGrantAccessUpdatesReposDocument
func (s *S) TestGrantAccessUpdatesReposDocument(c *gocheck.C) {
u, err := user.New("pippin", map[string]string{})
conn, err := db.Conn()
c.Assert(err, gocheck.IsNil)
defer conn.Close()
defer conn.User().Remove(bson.M{"_id": "pippin"})
c.Assert(err, gocheck.IsNil)
r := repository.Repository{Name: "onerepo"}
err = conn.Repository().Insert(&r)
c.Assert(err, gocheck.IsNil)
defer conn.Repository().Remove(bson.M{"_id": r.Name})
r2 := repository.Repository{Name: "otherepo"}
err = conn.Repository().Insert(&r2)
c.Assert(err, gocheck.IsNil)
defer conn.Repository().Remove(bson.M{"_id": r2.Name})
b := bytes.NewBufferString(fmt.Sprintf(`{"repositories": ["%s", "%s"], "users": ["%s"]}`, r.Name, r2.Name, u.Name))
rec, req := del("/repository/grant", b, c)
GrantAccess(rec, req)
var repos []repository.Repository
err = conn.Repository().Find(bson.M{"_id": bson.M{"$in": []string{r.Name, r2.Name}}}).All(&repos)
c.Assert(err, gocheck.IsNil)
c.Assert(rec.Code, gocheck.Equals, 200)
for _, repo := range repos {
c.Assert(repo.Users, gocheck.DeepEquals, []string{u.Name})
}
}
开发者ID:rochacon,项目名称:gandalf,代码行数:26,代码来源:handler_test.go
示例3: TestRemoveKeyShouldRemoveKeyFromAuthorizedKeysFile
func (s *S) TestRemoveKeyShouldRemoveKeyFromAuthorizedKeysFile(c *gocheck.C) {
u, err := user.New("Gandalf", map[string]string{"keyname": rawKey})
c.Assert(err, gocheck.IsNil)
defer user.Remove(u.Name)
url := "/user/Gandalf/key/keyname?:keyname=keyname&:name=Gandalf"
recorder, request := del(url, nil, c)
RemoveKey(recorder, request)
content := s.authKeysContent(c)
c.Assert(content, gocheck.Equals, "")
}
开发者ID:rochacon,项目名称:gandalf,代码行数:10,代码来源:handler_test.go
示例4: TestRemoveKeyGivesExpectedSuccessResponse
func (s *S) TestRemoveKeyGivesExpectedSuccessResponse(c *gocheck.C) {
u, err := user.New("Gandalf", map[string]string{"keyname": rawKey})
c.Assert(err, gocheck.IsNil)
defer user.Remove(u.Name)
url := "/user/Gandalf/key/keyname?:keyname=keyname&:name=Gandalf"
recorder, request := del(url, nil, c)
RemoveKey(recorder, request)
c.Assert(recorder.Code, gocheck.Equals, 200)
b := readBody(recorder.Body, c)
c.Assert(b, gocheck.Equals, `Key "keyname" successfully removed`)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:11,代码来源:handler_test.go
示例5: TestHasReadPermissionShouldReturnTrueWhenRepositoryIsNotPublicAndUserHasPermissionToRead
func (s *S) TestHasReadPermissionShouldReturnTrueWhenRepositoryIsNotPublicAndUserHasPermissionToRead(c *check.C) {
user, err := user.New("readonlyuser", map[string]string{})
c.Check(err, check.IsNil)
repo := &repository.Repository{
Name: "otherapp",
Users: []string{s.user.Name},
ReadOnlyUsers: []string{user.Name},
}
allowed := hasReadPermission(user, repo)
c.Assert(allowed, check.Equals, true)
}
开发者ID:ricardodani,项目名称:gandalf,代码行数:11,代码来源:gandalf_test.go
示例6: NewUser
func NewUser(w http.ResponseWriter, r *http.Request) {
var usr jsonUser
if err := parseBody(r.Body, &usr); err != nil {
http.Error(w, "Got error while parsing body: "+err.Error(), http.StatusBadRequest)
return
}
u, err := user.New(usr.Name, usr.Keys)
if err != nil {
http.Error(w, "Got error while creating user: "+err.Error(), http.StatusBadRequest)
return
}
fmt.Fprintf(w, "User \"%s\" successfully created\n", u.Name)
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:13,代码来源:handler.go
示例7: TestRemoveUser
func (s *S) TestRemoveUser(c *gocheck.C) {
u, err := user.New("username", map[string]string{})
c.Assert(err, gocheck.IsNil)
url := fmt.Sprintf("/user/%s/?:name=%s", u.Name, u.Name)
request, err := http.NewRequest("DELETE", url, nil)
c.Assert(err, gocheck.IsNil)
recorder := httptest.NewRecorder()
RemoveUser(recorder, request)
c.Assert(recorder.Code, gocheck.Equals, 200)
b, err := ioutil.ReadAll(recorder.Body)
c.Assert(err, gocheck.IsNil)
c.Assert(string(b), gocheck.Equals, "User \"username\" successfully removed\n")
}
开发者ID:rochacon,项目名称:gandalf,代码行数:13,代码来源:handler_test.go
示例8: TestListKeysWithoutKeysGivesEmptyJSON
func (s *S) TestListKeysWithoutKeysGivesEmptyJSON(c *gocheck.C) {
u, err := user.New("Gandalf", map[string]string{})
c.Assert(err, gocheck.IsNil)
defer user.Remove(u.Name)
url := "/user/Gandalf/keys?:name=Gandalf"
request, err := http.NewRequest("GET", url, nil)
c.Assert(err, gocheck.IsNil)
recorder := httptest.NewRecorder()
ListKeys(recorder, request)
c.Assert(recorder.Code, gocheck.Equals, 200)
b := readBody(recorder.Body, c)
c.Assert(b, gocheck.Equals, "{}")
}
开发者ID:rochacon,项目名称:gandalf,代码行数:13,代码来源:handler_test.go
示例9: TestRemoveKeyRemovesKeyFromDatabase
func (s *S) TestRemoveKeyRemovesKeyFromDatabase(c *gocheck.C) {
u, err := user.New("Gandalf", map[string]string{"keyname": rawKey})
c.Assert(err, gocheck.IsNil)
defer user.Remove(u.Name)
url := "/user/Gandalf/key/keyname?:keyname=keyname&:name=Gandalf"
recorder, request := del(url, nil, c)
RemoveKey(recorder, request)
conn, err := db.Conn()
c.Assert(err, gocheck.IsNil)
defer conn.Close()
count, err := conn.Key().Find(bson.M{"name": "keyname", "username": "Gandalf"}).Count()
c.Assert(err, gocheck.IsNil)
c.Assert(count, gocheck.Equals, 0)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:14,代码来源:handler_test.go
示例10: TestRemoveUserShouldRemoveFromDB
func (s *S) TestRemoveUserShouldRemoveFromDB(c *gocheck.C) {
u, err := user.New("anuser", map[string]string{})
c.Assert(err, gocheck.IsNil)
url := fmt.Sprintf("/user/%s/?:name=%s", u.Name, u.Name)
request, err := http.NewRequest("DELETE", url, nil)
c.Assert(err, gocheck.IsNil)
recorder := httptest.NewRecorder()
RemoveUser(recorder, request)
conn, err := db.Conn()
c.Assert(err, gocheck.IsNil)
defer conn.Close()
collection := conn.User()
lenght, err := collection.Find(bson.M{"_id": u.Name}).Count()
c.Assert(err, gocheck.IsNil)
c.Assert(lenght, gocheck.Equals, 0)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:16,代码来源:handler_test.go
示例11: SetUpSuite
func (s *S) SetUpSuite(c *gocheck.C) {
var err error
log, err = syslog.New(syslog.LOG_INFO, "gandalf-listener")
c.Check(err, gocheck.IsNil)
err = config.ReadConfigFile("../etc/gandalf.conf")
c.Check(err, gocheck.IsNil)
config.Set("database:name", "gandalf_bin_tests")
s.user, err = user.New("testuser", map[string]string{})
c.Check(err, gocheck.IsNil)
// does not uses repository.New to avoid creation of bare git repo
s.repo = &repository.Repository{Name: "myapp", Users: []string{s.user.Name}}
conn, err := db.Conn()
c.Assert(err, gocheck.IsNil)
defer conn.Close()
err = conn.Repository().Insert(s.repo)
c.Check(err, gocheck.IsNil)
}
开发者ID:heynemann,项目名称:gandalf,代码行数:17,代码来源:gandalf_test.go
示例12: TestListKeysGivesExpectedSuccessResponse
func (s *S) TestListKeysGivesExpectedSuccessResponse(c *gocheck.C) {
keys := map[string]string{"key1": rawKey, "key2": otherKey}
u, err := user.New("Gandalf", keys)
c.Assert(err, gocheck.IsNil)
defer user.Remove(u.Name)
url := "/user/Gandalf/keys?:name=Gandalf"
request, err := http.NewRequest("GET", url, nil)
c.Assert(err, gocheck.IsNil)
recorder := httptest.NewRecorder()
ListKeys(recorder, request)
c.Assert(recorder.Code, gocheck.Equals, 200)
body, err := ioutil.ReadAll(recorder.Body)
c.Assert(err, gocheck.IsNil)
var data map[string]string
err = json.Unmarshal(body, &data)
c.Assert(err, gocheck.IsNil)
c.Assert(data, gocheck.DeepEquals, keys)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:18,代码来源:handler_test.go
示例13: newUser
func newUser(w http.ResponseWriter, r *http.Request) {
var usr jsonUser
if err := parseBody(r.Body, &usr); err != nil {
http.Error(w, "Got error while parsing body: "+err.Error(), http.StatusBadRequest)
return
}
u, err := user.New(usr.Name, usr.Keys)
if err != nil {
status := http.StatusInternalServerError
if err == user.ErrUserAlreadyExists {
status = http.StatusConflict
}
if _, ok := err.(*user.InvalidUserError); ok {
status = http.StatusBadRequest
}
http.Error(w, err.Error(), status)
return
}
fmt.Fprintf(w, "User \"%s\" successfully created\n", u.Name)
}
开发者ID:ricardodani,项目名称:gandalf,代码行数:20,代码来源:handler.go
示例14: TestAddKey
func (s *S) TestAddKey(c *gocheck.C) {
usr, err := user.New("Frodo", map[string]string{})
c.Assert(err, gocheck.IsNil)
defer user.Remove(usr.Name)
b := strings.NewReader(fmt.Sprintf(`{"keyname": %q}`, rawKey))
recorder, request := post(fmt.Sprintf("/user/%s/key?:name=%s", usr.Name, usr.Name), b, c)
AddKey(recorder, request)
got := readBody(recorder.Body, c)
expected := "Key(s) successfully created"
c.Assert(got, gocheck.Equals, expected)
c.Assert(recorder.Code, gocheck.Equals, 200)
var k user.Key
conn, err := db.Conn()
c.Assert(err, gocheck.IsNil)
defer conn.Close()
err = conn.Key().Find(bson.M{"name": "keyname", "username": usr.Name}).One(&k)
c.Assert(err, gocheck.IsNil)
c.Assert(k.Body, gocheck.Equals, keyBody)
c.Assert(k.Comment, gocheck.Equals, keyComment)
}
开发者ID:rochacon,项目名称:gandalf,代码行数:20,代码来源:handler_test.go
注:本文中的github.com/tsuru/gandalf/user.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论