@@ -17,67 +17,22 @@ import (
1717
1818// TestSignup sets up a test instance of Teleport and runs a playwright test against it to test the signup flow.
1919func TestSignup (t * testing.T ) {
20- rc , ctx := helpers .CreateTeleportTestInstance (t )
21-
22- as := rc .Process .GetAuthServer ()
23-
24- accessRole := services .NewPresetAccessRole ()
25-
26- // Create a test user.
27- testUser , err := types .NewUser ("testuser" )
28- require .NoError (t , err )
29- testUser .SetRoles ([]string {accessRole .GetName ()})
30- user , err := as .UpsertUser (ctx , testUser )
31-
32- inviteToken , err := as .CreateResetPasswordToken (ctx , authclient.CreateUserTokenRequest {
33- Name : user .GetName (),
34- })
35- require .NoError (t , err )
36-
37- // Generate the URL the playwright test will start from.
38- startUrl := fmt .Sprintf ("START_URL=https://%s/web/invite/%s" , rc .Web , inviteToken .GetName ())
39-
40- // Start the playwright test
41- cmd := exec .Command ("pnpm" , "test-e2e" , "signup.spec.ts" )
42- cmd .Env = append (os .Environ (), startUrl )
43- cmd .Stdout = os .Stdout
44- cmd .Stderr = os .Stderr
45- require .NoError (t , cmd .Run ())
20+ setupAndRunBasicTest (t , "signup.spec.ts" )
4621}
4722
4823// TestCreateNewRole sets up a test instance of Teleport and a user to test role management in the UI.
4924func TestRoleManagement (t * testing.T ) {
50- rc , ctx := helpers .CreateTeleportTestInstance (t )
51-
52- as := rc .Process .GetAuthServer ()
53-
54- accessRole := services .NewPresetAccessRole ()
55- editorRole := services .NewPresetEditorRole ()
56-
57- // Create a test user.
58- testUser , err := types .NewUser ("testuser" )
59- require .NoError (t , err )
60- testUser .SetRoles ([]string {accessRole .GetName (), editorRole .GetName ()})
61- user , err := as .UpsertUser (ctx , testUser )
62-
63- inviteToken , err := as .CreateResetPasswordToken (ctx , authclient.CreateUserTokenRequest {
64- Name : user .GetName (),
65- })
66- require .NoError (t , err )
67-
68- // Generate the URL the playwright test will start from.
69- startUrl := fmt .Sprintf ("START_URL=https://%s/web/invite/%s" , rc .Web , inviteToken .GetName ())
70-
71- // Start the playwright test
72- cmd := exec .Command ("pnpm" , "test-e2e" , "roles.spec.ts" )
73- cmd .Env = append (os .Environ (), startUrl )
74- cmd .Stdout = os .Stdout
75- cmd .Stderr = os .Stderr
76- require .NoError (t , cmd .Run ())
25+ setupAndRunBasicTest (t , "roles.spec.ts" )
7726}
7827
7928// TestAuthConnectorManagement sets up a test instance of Teleport and a user to test auth connector management in the UI.
8029func TestAuthConnectorManagement (t * testing.T ) {
30+ setupAndRunBasicTest (t , "authconnectors.spec.ts" )
31+ }
32+
33+ // setupAndRunBasicTest sets up a test instance of Teleport and a user with the access and editor roles and runs a playwright test.
34+ // This is a helper function in cases where there is no additional backend setup required beyond creating an invite link.
35+ func setupAndRunBasicTest (t * testing.T , playwrightTest string ) {
8136 rc , ctx := helpers .CreateTeleportTestInstance (t )
8237
8338 as := rc .Process .GetAuthServer ()
@@ -90,6 +45,7 @@ func TestAuthConnectorManagement(t *testing.T) {
9045 require .NoError (t , err )
9146 testUser .SetRoles ([]string {accessRole .GetName (), editorRole .GetName ()})
9247 user , err := as .UpsertUser (ctx , testUser )
48+ require .NoError (t , err )
9349
9450 inviteToken , err := as .CreateResetPasswordToken (ctx , authclient.CreateUserTokenRequest {
9551 Name : user .GetName (),
@@ -100,7 +56,7 @@ func TestAuthConnectorManagement(t *testing.T) {
10056 startUrl := fmt .Sprintf ("START_URL=https://%s/web/invite/%s" , rc .Web , inviteToken .GetName ())
10157
10258 // Start the playwright test
103- cmd := exec .Command ("pnpm" , "test-e2e" , "authconnectors.spec.ts " )
59+ cmd := exec .Command ("pnpm" , "test-e2e" , playwrightTest , "--headed " )
10460 cmd .Env = append (os .Environ (), startUrl )
10561 cmd .Stdout = os .Stdout
10662 cmd .Stderr = os .Stderr
0 commit comments