Skip to content

Commit

Permalink
Merge pull request #8581 from concourse/fix-team-name-overwritten-6-7
Browse files Browse the repository at this point in the history
fix team_name overwritten bug
  • Loading branch information
syslxg authored Oct 5, 2022
2 parents a017ce9 + 53753f8 commit ba88583
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 10 deletions.
4 changes: 2 additions & 2 deletions atc/api/auth/check_pipeline_access_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type checkPipelineAccessHandler struct {
}

func (h checkPipelineAccessHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
teamName := r.FormValue(":team_name")
pipelineName := r.FormValue(":pipeline_name")
teamName := r.URL.Query().Get(":team_name")
pipelineName := r.URL.Query().Get(":pipeline_name")

team, found, err := h.teamFactory.FindTeam(teamName)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions atc/api/pipelineserver/reject_archived_handler_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type RejectArchivedHandler struct {
}

func (ra RejectArchivedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
teamName := r.FormValue(":team_name")
pipelineName := r.FormValue(":pipeline_name")
teamName := r.URL.Query().Get(":team_name")
pipelineName := r.URL.Query().Get(":pipeline_name")

team, found, err := ra.teamFactory.FindTeam(teamName)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions atc/api/pipelineserver/scoped_handler_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func NewScopedHandlerFactory(

func (pdbh *ScopedHandlerFactory) HandlerFor(pipelineScopedHandler func(db.Pipeline) http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
teamName := r.FormValue(":team_name")
pipelineName := r.FormValue(":pipeline_name")
teamName := r.URL.Query().Get(":team_name")
pipelineName := r.URL.Query().Get(":pipeline_name")

pipeline, ok := r.Context().Value(auth.PipelineContextKey).(db.Pipeline)
if !ok {
Expand Down
24 changes: 24 additions & 0 deletions atc/api/pipelineserver/scoped_handler_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"net/http"
"net/http/httptest"
"net/url"
"strings"

"github.com/concourse/concourse/atc/api/auth"
"github.com/concourse/concourse/atc/api/pipelineserver"
Expand Down Expand Up @@ -107,6 +109,28 @@ var _ = Describe("Handler", func() {
Expect(dbTeamFactory.FindTeamArgsForCall(0)).To(Equal("some-team"))
})

Context("when the request has team name in body with content-type application/x-www-form-urlencoded", func() {
JustBeforeEach(func() {
body := url.Values{
":team_name": {"some-other-team"},
}

request, err := http.NewRequest("POST", server.URL+"?:team_name=some-team&:pipeline_name=some-pipeline", strings.NewReader(body.Encode()))
Expect(err).NotTo(HaveOccurred())

request.Header.Add("Content-type", "application/x-www-form-urlencoded")

response, err = new(http.Client).Do(request)
Expect(err).NotTo(HaveOccurred())
})

It("looks up the team by the team name in URL", func() {
Expect(dbTeamFactory.FindTeamCallCount()).To(Equal(2))
Expect(dbTeamFactory.FindTeamArgsForCall(1)).To(Equal("some-team"))

})
})

Context("when the pipeline exists", func() {
BeforeEach(func() {
fakePipeline.NameReturns("some-pipeline")
Expand Down
2 changes: 1 addition & 1 deletion atc/api/policychecker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c *checker) Check(action string, acc accessor.Access, req *http.Request) (
return policy.PassedPolicyCheck(), nil
}

team := req.FormValue(":team_name")
team := req.URL.Query().Get(":team_name")
input := policy.PolicyCheckInput{
HttpMethod: req.Method,
Action: action,
Expand Down
2 changes: 1 addition & 1 deletion atc/api/policychecker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var _ = Describe("PolicyChecker", func() {
Context("when every is ok", func() {
BeforeEach(func() {
fakeAccess.TeamRolesReturns(map[string][]string{
"some-team": []string{"some-role"},
"some-team": {"some-role"},
})
fakeAccess.ClaimsReturns(accessor.Claims{UserName: "some-user"})
body := bytes.NewBuffer([]byte("a: b"))
Expand Down
2 changes: 1 addition & 1 deletion atc/api/team_scoped_handler_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (f *TeamScopedHandlerFactory) HandlerFor(teamScopedHandler func(db.Team) ht
logger := f.logger.Session("team-scoped-handler")
acc := accessor.GetAccessor(r)

teamName := r.FormValue(":team_name")
teamName := r.URL.Query().Get(":team_name")

if acc.IsAuthorized(teamName) {
team, found, err := f.teamFactory.FindTeam(teamName)
Expand Down
2 changes: 1 addition & 1 deletion atc/api/teamserver/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *Server) SetTeam(w http.ResponseWriter, r *http.Request) {

acc := accessor.GetAccessor(r)

teamName := r.FormValue(":team_name")
teamName := r.URL.Query().Get(":team_name")

var atcTeam atc.Team
err := json.NewDecoder(r.Body).Decode(&atcTeam)
Expand Down

0 comments on commit ba88583

Please sign in to comment.