@@ -1902,6 +1902,126 @@ func TestGetUsers(t *testing.T) {
1902
1902
require .Len (t , res .Users , 1 )
1903
1903
require .Equal (t , res .Users [0 ].ID , first .UserID )
1904
1904
})
1905
+
1906
+ t .Run ("LoginTypeNoneFilter" , func (t * testing.T ) {
1907
+ t .Parallel ()
1908
+ client := coderdtest .New (t , nil )
1909
+ first := coderdtest .CreateFirstUser (t , client )
1910
+ ctx := testutil .Context (t , testutil .WaitLong )
1911
+
1912
+ _ , err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
1913
+
1914
+ Username : "bob" ,
1915
+ OrganizationIDs : []uuid.UUID {first .OrganizationID },
1916
+ UserLoginType : codersdk .LoginTypeNone ,
1917
+ })
1918
+ require .NoError (t , err )
1919
+
1920
+ res , err := client .Users (ctx , codersdk.UsersRequest {
1921
+ LoginType : []codersdk.LoginType {codersdk .LoginTypeNone },
1922
+ })
1923
+ require .NoError (t , err )
1924
+ require .Len (t , res .Users , 1 )
1925
+ require .Equal (t , res .Users [0 ].LoginType , codersdk .LoginTypeNone )
1926
+ })
1927
+
1928
+ t .Run ("LoginTypeMultipleFilter" , func (t * testing.T ) {
1929
+ t .Parallel ()
1930
+ client := coderdtest .New (t , nil )
1931
+ first := coderdtest .CreateFirstUser (t , client )
1932
+ ctx := testutil .Context (t , testutil .WaitLong )
1933
+ filtered := make ([]codersdk.User , 0 )
1934
+
1935
+ bob , err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
1936
+
1937
+ Username : "bob" ,
1938
+ OrganizationIDs : []uuid.UUID {first .OrganizationID },
1939
+ UserLoginType : codersdk .LoginTypeNone ,
1940
+ })
1941
+ require .NoError (t , err )
1942
+ filtered = append (filtered , bob )
1943
+
1944
+ charlie , err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
1945
+
1946
+ Username : "charlie" ,
1947
+ OrganizationIDs : []uuid.UUID {first .OrganizationID },
1948
+ UserLoginType : codersdk .LoginTypeGithub ,
1949
+ })
1950
+ require .NoError (t , err )
1951
+ filtered = append (filtered , charlie )
1952
+
1953
+ res , err := client .Users (ctx , codersdk.UsersRequest {
1954
+ LoginType : []codersdk.LoginType {codersdk .LoginTypeNone , codersdk .LoginTypeGithub },
1955
+ })
1956
+ require .NoError (t , err )
1957
+ require .Len (t , res .Users , 2 )
1958
+ require .ElementsMatch (t , filtered , res .Users )
1959
+ })
1960
+
1961
+ t .Run ("DormantUserWithLoginTypeNone" , func (t * testing.T ) {
1962
+ t .Parallel ()
1963
+ client := coderdtest .New (t , nil )
1964
+ first := coderdtest .CreateFirstUser (t , client )
1965
+ ctx := testutil .Context (t , testutil .WaitLong )
1966
+
1967
+ _ , err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
1968
+
1969
+ Username : "bob" ,
1970
+ OrganizationIDs : []uuid.UUID {first .OrganizationID },
1971
+ UserLoginType : codersdk .LoginTypeNone ,
1972
+ })
1973
+ require .NoError (t , err )
1974
+
1975
+ _ , err = client .UpdateUserStatus (ctx , "bob" , codersdk .UserStatusSuspended )
1976
+ require .NoError (t , err )
1977
+
1978
+ res , err := client .Users (ctx , codersdk.UsersRequest {
1979
+ Status : codersdk .UserStatusSuspended ,
1980
+ LoginType : []codersdk.LoginType {codersdk .LoginTypeNone , codersdk .LoginTypeGithub },
1981
+ })
1982
+ require .NoError (t , err )
1983
+ require .Len (t , res .Users , 1 )
1984
+ require .Equal (t , res .Users [0 ].Username , "bob" )
1985
+ require .Equal (t , res .Users [0 ].Status , codersdk .UserStatusSuspended )
1986
+ require .Equal (t , res .Users [0 ].LoginType , codersdk .LoginTypeNone )
1987
+ })
1988
+
1989
+ t .Run ("LoginTypeOidcFromMultipleUser" , func (t * testing.T ) {
1990
+ t .Parallel ()
1991
+ client := coderdtest .New (t , & coderdtest.Options {
1992
+ OIDCConfig : & coderd.OIDCConfig {
1993
+ AllowSignups : true ,
1994
+ },
1995
+ })
1996
+ first := coderdtest .CreateFirstUser (t , client )
1997
+ ctx := testutil .Context (t , testutil .WaitLong )
1998
+
1999
+ _ , err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
2000
+
2001
+ Username : "bob" ,
2002
+ OrganizationIDs : []uuid.UUID {first .OrganizationID },
2003
+ UserLoginType : codersdk .LoginTypeOIDC ,
2004
+ })
2005
+ require .NoError (t , err )
2006
+
2007
+ for i := range 5 {
2008
+ _ , err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
2009
+ Email :
fmt .
Sprintf (
"%[email protected] " ,
i ),
2010
+ Username : fmt .Sprintf ("user%d" , i ),
2011
+ OrganizationIDs : []uuid.UUID {first .OrganizationID },
2012
+ UserLoginType : codersdk .LoginTypeNone ,
2013
+ })
2014
+ require .NoError (t , err )
2015
+ }
2016
+
2017
+ res , err := client .Users (ctx , codersdk.UsersRequest {
2018
+ LoginType : []codersdk.LoginType {codersdk .LoginTypeOIDC },
2019
+ })
2020
+ require .NoError (t , err )
2021
+ require .Len (t , res .Users , 1 )
2022
+ require .Equal (t , res .Users [0 ].Username , "bob" )
2023
+ require .Equal (t , res .Users [0 ].LoginType , codersdk .LoginTypeOIDC )
2024
+ })
1905
2025
}
1906
2026
1907
2027
func TestGetUsersPagination (t * testing.T ) {
0 commit comments