@@ -15,6 +15,7 @@ import (
15
15
"github.com/coder/coder/v2/coderd/coderdtest/oidctest"
16
16
"github.com/coder/coder/v2/coderd/database"
17
17
"github.com/coder/coder/v2/coderd/database/dbauthz"
18
+ "github.com/coder/coder/v2/coderd/database/dbtestutil"
18
19
"github.com/coder/coder/v2/coderd/rbac"
19
20
"github.com/coder/coder/v2/coderd/util/slice"
20
21
"github.com/coder/coder/v2/codersdk"
@@ -683,7 +684,10 @@ func TestGroupSync(t *testing.T) {
683
684
}
684
685
}
685
686
686
- func TestUserLogin (t * testing.T ) {
687
+ func TestEnterpriseUserLogin (t * testing.T ) {
688
+ t .Parallel ()
689
+
690
+ // Login to a user with a custom organization role set.
687
691
t .Run ("CustomRole" , func (t * testing.T ) {
688
692
t .Parallel ()
689
693
dv := coderdtest .DeploymentValues (t )
@@ -714,15 +718,58 @@ func TestUserLogin(t *testing.T) {
714
718
OrganizationID : owner .OrganizationID ,
715
719
},
716
720
}, func (r * codersdk.CreateUserRequest ) {
717
- r .Password = ""
718
- r .UserLoginType = codersdk .LoginTypeNone
721
+ r .Password = "SomeSecurePassword!"
722
+ r .UserLoginType = codersdk .LoginTypePassword
723
+ })
724
+
725
+ _ , err = anotherClient .LoginWithPassword (ctx , codersdk.LoginWithPasswordRequest {
726
+ Email : anotherUser .Email ,
727
+ Password : "SomeSecurePassword!" ,
728
+ })
729
+ require .NoError (t , err )
730
+ })
731
+
732
+ // Login to a user with a custom organization role that no longer exists
733
+ t .Run ("DeletedRole" , func (t * testing.T ) {
734
+ t .Parallel ()
735
+
736
+ // The dbauthz layer protects against deleted roles. So use the underlying
737
+ // database directly to corrupt it.
738
+ rawDB , pubsub := dbtestutil .NewDB (t )
739
+
740
+ dv := coderdtest .DeploymentValues (t )
741
+ dv .Experiments = []string {string (codersdk .ExperimentCustomRoles )}
742
+ ownerClient , owner := coderdenttest .New (t , & coderdenttest.Options {
743
+ Options : & coderdtest.Options {
744
+ DeploymentValues : dv ,
745
+ Database : rawDB ,
746
+ Pubsub : pubsub ,
747
+ },
748
+ LicenseOptions : & coderdenttest.LicenseOptions {
749
+ Features : license.Features {
750
+ codersdk .FeatureCustomRoles : 1 ,
751
+ },
752
+ },
753
+ })
754
+
755
+ anotherClient , anotherUser := coderdtest .CreateAnotherUserMutators (t , ownerClient , owner .OrganizationID , nil , func (r * codersdk.CreateUserRequest ) {
756
+ r .Password = "SomeSecurePassword!"
757
+ r .UserLoginType = codersdk .LoginTypePassword
758
+ })
759
+
760
+ ctx := testutil .Context (t , testutil .WaitShort )
761
+ _ , err := rawDB .UpdateMemberRoles (ctx , database.UpdateMemberRolesParams {
762
+ GrantedRoles : []string {"not-exists" },
763
+ UserID : anotherUser .ID ,
764
+ OrgID : owner .OrganizationID ,
719
765
})
766
+ require .NoError (t , err , "assign not-exists role" )
720
767
721
- _ , err = anotherClient .LoginWithPassword (context . Background () , codersdk.LoginWithPasswordRequest {
768
+ _ , err = anotherClient .LoginWithPassword (ctx , codersdk.LoginWithPasswordRequest {
722
769
Email : anotherUser .Email ,
723
770
Password : "SomeSecurePassword!" ,
724
771
})
725
- require .Error (t , err )
772
+ require .NoError (t , err )
726
773
})
727
774
}
728
775
0 commit comments