18097: Adds more tests.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Fri, 17 Sep 2021 14:44:11 +0000 (11:44 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Fri, 17 Sep 2021 14:44:11 +0000 (11:44 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

tools/sync-groups/sync-groups_test.go

index c176210847b1f01e843c31664c4010e25ab84171..69326c98d958cacd7709d24c47b9c63abd690b78 100644 (file)
@@ -187,11 +187,12 @@ func RemoteGroupExists(cfg *ConfigParams, groupName string) (uuid string, err er
 
 func (s *TestSuite) TestParseFlagsWithPositionalArgument(c *C) {
        cfg := ConfigParams{}
-       os.Args = []string{"cmd", "-verbose", "/tmp/somefile.csv"}
+       os.Args = []string{"cmd", "-verbose", "-case-insensitive", "/tmp/somefile.csv"}
        err := ParseFlags(&cfg)
        c.Assert(err, IsNil)
        c.Check(cfg.Path, Equals, "/tmp/somefile.csv")
        c.Check(cfg.Verbose, Equals, true)
+       c.Check(cfg.CaseInsensitive, Equals, true)
 }
 
 func (s *TestSuite) TestParseFlagsWithoutPositionalArgument(c *C) {
@@ -533,3 +534,39 @@ func (s *TestSuite) TestUseUsernamesWithCaseInsensitiveMatching(c *C) {
        c.Assert(groupUUID, Not(Equals), "")
        c.Assert(GroupMembershipExists(s.cfg.Client, activeUserUUID, groupUUID, "can_write"), Equals, true)
 }
+
+func (s *TestSuite) TestUsernamesCaseInsensitiveCollision(c *C) {
+       activeUserName := s.users[arvadostest.ActiveUserUUID].Username
+       activeUserUUID := s.users[arvadostest.ActiveUserUUID].UUID
+
+       nu := arvados.User{}
+       nuUsername := strings.ToUpper(activeUserName)
+       err := s.cfg.Client.RequestAndDecode(&nu, "POST", "/arvados/v1/users", nil, map[string]interface{}{
+               "user": map[string]string{
+                       "username": nuUsername,
+               },
+       })
+       c.Assert(err, IsNil)
+
+       // Manually remove non-fixture user because /database/reset fails otherwise
+       defer s.cfg.Client.RequestAndDecode(nil, "DELETE", "/arvados/v1/users/"+nu.UUID, nil, nil)
+
+       c.Assert(nu.Username, Equals, nuUsername)
+       c.Assert(nu.UUID, Not(Equals), activeUserUUID)
+       c.Assert(nu.Username, Not(Equals), activeUserName)
+
+       data := [][]string{
+               {"SomeGroup", activeUserName},
+       }
+       tmpfile, err := MakeTempCSVFile(data)
+       c.Assert(err, IsNil)
+       defer os.Remove(tmpfile.Name()) // clean up
+
+       s.cfg.Path = tmpfile.Name()
+       s.cfg.UserID = "username"
+       s.cfg.CaseInsensitive = true
+       err = doMain(s.cfg)
+       // Should get an error because of "ACTIVE" and "Active" usernames
+       c.Assert(err, NotNil)
+       c.Assert(err, ErrorMatches, ".*case insensitive collision.*")
+}