func (cmd *ATCCommand) updateBasicAuthCredentials(sqlDB db.DB) error { var team db.Team if cmd.BasicAuth.Username != "" && cmd.BasicAuth.Password != "" { team = db.Team{ Name: atc.DefaultTeamName, BasicAuth: db.BasicAuth{ BasicAuthUsername: cmd.BasicAuth.Username, BasicAuthPassword: cmd.BasicAuth.Password, }, } } else { team = db.Team{Name: atc.DefaultTeamName} } _, err := sqlDB.UpdateTeamBasicAuth(team) return err }
OrganizationName: "org1", TeamName: "teama", }, { OrganizationName: "org2", TeamName: "teamb", }, }, Users: []string{"user1", "user2", "user3"}, }, } }) It("saves basic auth team info to the existing team", func() { savedTeam, err := database.UpdateTeamBasicAuth(basicAuthTeam) Expect(err).NotTo(HaveOccurred()) Expect(savedTeam.BasicAuthUsername).To(Equal(basicAuthTeam.BasicAuthUsername)) Expect(bcrypt.CompareHashAndPassword([]byte(savedTeam.BasicAuthPassword), []byte(basicAuthTeam.BasicAuthPassword))).To(BeNil()) }) Context("required basic auth elements are not present", func() { BeforeEach(func() { _, err := database.UpdateTeamBasicAuth(basicAuthTeam) Expect(err).NotTo(HaveOccurred()) }) It("nulls basic auth when has a blank username", func() { basicAuthTeam.BasicAuthUsername = ""