custom token is ignored when creating a user
This commit is contained in:
parent
4a1c639452
commit
97116f01c2
4 changed files with 19 additions and 6 deletions
|
@ -196,7 +196,7 @@ func (s Server) Handler() http.Handler {
|
|||
|
||||
r.Route("/builds", func(r chi.Router) {
|
||||
r.Get("/", builds.HandleList(s.Repos, s.Builds))
|
||||
r.With(acl.CheckWriteAccess()).Post("/", builds.HandleCreate(s.Repos, s.Commits, s.Triggerer))
|
||||
r.With(acl.CheckWriteAccess()).Post("/", builds.HandleCreate(s.Users, s.Repos, s.Commits, s.Triggerer))
|
||||
|
||||
r.Get("/branches", branches.HandleList(s.Repos, s.Builds))
|
||||
r.With(acl.CheckWriteAccess()).Delete("/branches/*", branches.HandleDelete(s.Repos, s.Builds))
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
// HandleCreate returns an http.HandlerFunc that processes http
|
||||
// requests to create a build for the specified commit.
|
||||
func HandleCreate(
|
||||
users core.UserStore,
|
||||
repos core.RepositoryStore,
|
||||
commits core.CommitService,
|
||||
triggerer core.Triggerer,
|
||||
|
@ -48,6 +49,12 @@ func HandleCreate(
|
|||
return
|
||||
}
|
||||
|
||||
owner, err := users.Find(ctx, repo.UserID)
|
||||
if err != nil {
|
||||
render.NotFound(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
// if the user does not provide a branch, assume the
|
||||
// default repository branch.
|
||||
if branch == "" {
|
||||
|
@ -58,9 +65,9 @@ func HandleCreate(
|
|||
|
||||
var commit *core.Commit
|
||||
if sha != "" {
|
||||
commit, err = commits.Find(ctx, user, repo.Slug, sha)
|
||||
commit, err = commits.Find(ctx, owner, repo.Slug, sha)
|
||||
} else {
|
||||
commit, err = commits.FindRef(ctx, user, repo.Slug, ref)
|
||||
commit, err = commits.FindRef(ctx, owner, repo.Slug, ref)
|
||||
}
|
||||
if err != nil {
|
||||
render.NotFound(w, err)
|
||||
|
|
|
@ -83,6 +83,9 @@ func TestCreate(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
users := mock.NewMockUserStore(controller)
|
||||
users.EXPECT().Find(gomock.Any(), mockRepo.UserID).Return(mockUser, nil)
|
||||
|
||||
repos := mock.NewMockRepositoryStore(controller)
|
||||
repos.EXPECT().FindName(gomock.Any(), gomock.Any(), mockRepo.Name).Return(mockRepo, nil)
|
||||
|
||||
|
@ -106,7 +109,7 @@ func TestCreate(t *testing.T) {
|
|||
context.WithValue(request.WithUser(r.Context(), mockUser), chi.RouteCtxKey, c),
|
||||
)
|
||||
|
||||
HandleCreate(repos, commits, triggerer)(w, r)
|
||||
HandleCreate(users, repos, commits, triggerer)(w, r)
|
||||
if got, want := w.Code, 200; want != got {
|
||||
t.Errorf("Want response code %d, got %d", want, got)
|
||||
}
|
||||
|
@ -135,6 +138,9 @@ func TestCreate_FromHead(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
users := mock.NewMockUserStore(controller)
|
||||
users.EXPECT().Find(gomock.Any(), mockRepo.UserID).Return(mockUser, nil)
|
||||
|
||||
repos := mock.NewMockRepositoryStore(controller)
|
||||
repos.EXPECT().FindName(gomock.Any(), gomock.Any(), mockRepo.Name).Return(mockRepo, nil)
|
||||
|
||||
|
@ -154,7 +160,7 @@ func TestCreate_FromHead(t *testing.T) {
|
|||
context.WithValue(request.WithUser(r.Context(), mockUser), chi.RouteCtxKey, c),
|
||||
)
|
||||
|
||||
HandleCreate(repos, commits, triggerer)(w, r)
|
||||
HandleCreate(users, repos, commits, triggerer)(w, r)
|
||||
if got, want := w.Code, 200; want != got {
|
||||
t.Errorf("Want response code %d, got %d", want, got)
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func HandleCreate(users core.UserStore, service core.UserService, sender core.We
|
|||
Machine: in.Machine,
|
||||
Created: time.Now().Unix(),
|
||||
Updated: time.Now().Unix(),
|
||||
Hash: in.Hash,
|
||||
Hash: in.Token,
|
||||
}
|
||||
if user.Hash == "" {
|
||||
user.Hash = uniuri.NewLen(32)
|
||||
|
|
Loading…
Reference in a new issue