@@ -12,158 +12,162 @@ import {
12
12
} from "../helpers" ;
13
13
import { beforeCoderTest , resetExternalAuthKey } from "../hooks" ;
14
14
15
- test . beforeAll ( async ( { baseURL } ) => {
16
- const srv = await createServer ( gitAuth . webPort ) ;
15
+ test . describe . skip ( "externalAuth" , ( ) => {
16
+ test . beforeAll ( async ( { baseURL } ) => {
17
+ const srv = await createServer ( gitAuth . webPort ) ;
17
18
18
- // The GitHub validate endpoint returns the currently authenticated user!
19
- srv . use ( gitAuth . validatePath , ( req , res ) => {
20
- res . write ( JSON . stringify ( ghUser ) ) ;
21
- res . end ( ) ;
19
+ // The GitHub validate endpoint returns the currently authenticated user!
20
+ srv . use ( gitAuth . validatePath , ( req , res ) => {
21
+ res . write ( JSON . stringify ( ghUser ) ) ;
22
+ res . end ( ) ;
23
+ } ) ;
24
+ srv . use ( gitAuth . tokenPath , ( req , res ) => {
25
+ const r = ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 7 ) ;
26
+ res . write ( JSON . stringify ( { access_token : r } ) ) ;
27
+ res . end ( ) ;
28
+ } ) ;
29
+ srv . use ( gitAuth . authPath , ( req , res ) => {
30
+ res . redirect (
31
+ `${ baseURL } /external-auth/${ gitAuth . webProvider } /callback?code=1234&state=${ req . query . state } ` ,
32
+ ) ;
33
+ } ) ;
22
34
} ) ;
23
- srv . use ( gitAuth . tokenPath , ( req , res ) => {
24
- const r = ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 7 ) ;
25
- res . write ( JSON . stringify ( { access_token : r } ) ) ;
26
- res . end ( ) ;
27
- } ) ;
28
- srv . use ( gitAuth . authPath , ( req , res ) => {
29
- res . redirect (
30
- `${ baseURL } /external-auth/${ gitAuth . webProvider } /callback?code=1234&state=${ req . query . state } ` ,
31
- ) ;
35
+
36
+ test . beforeEach ( async ( { context, page } ) => {
37
+ beforeCoderTest ( page ) ;
38
+ await login ( page ) ;
39
+ await resetExternalAuthKey ( context ) ;
32
40
} ) ;
33
- } ) ;
34
41
35
- test . beforeEach ( async ( { context, page } ) => {
36
- beforeCoderTest ( page ) ;
37
- await login ( page ) ;
38
- await resetExternalAuthKey ( context ) ;
39
- } ) ;
42
+ // Ensures that a Git auth provider with the device flow functions and completes!
43
+ test ( "external auth device" , async ( { page } ) => {
44
+ const device : ExternalAuthDevice = {
45
+ device_code : "1234" ,
46
+ user_code : "1234-5678" ,
47
+ expires_in : 900 ,
48
+ interval : 1 ,
49
+ verification_uri : "" ,
50
+ } ;
40
51
41
- // Ensures that a Git auth provider with the device flow functions and completes!
42
- test ( "external auth device" , async ( { page } ) => {
43
- const device : ExternalAuthDevice = {
44
- device_code : "1234" ,
45
- user_code : "1234-5678" ,
46
- expires_in : 900 ,
47
- interval : 1 ,
48
- verification_uri : "" ,
49
- } ;
52
+ // Start a server to mock the GitHub API.
53
+ const srv = await createServer ( gitAuth . devicePort ) ;
54
+ srv . use ( gitAuth . validatePath , ( req , res ) => {
55
+ res . write ( JSON . stringify ( ghUser ) ) ;
56
+ res . end ( ) ;
57
+ } ) ;
58
+ srv . use ( gitAuth . codePath , ( req , res ) => {
59
+ res . write ( JSON . stringify ( device ) ) ;
60
+ res . end ( ) ;
61
+ } ) ;
62
+ srv . use ( gitAuth . installationsPath , ( req , res ) => {
63
+ res . write ( JSON . stringify ( ghInstall ) ) ;
64
+ res . end ( ) ;
65
+ } ) ;
50
66
51
- // Start a server to mock the GitHub API.
52
- const srv = await createServer ( gitAuth . devicePort ) ;
53
- srv . use ( gitAuth . validatePath , ( req , res ) => {
54
- res . write ( JSON . stringify ( ghUser ) ) ;
55
- res . end ( ) ;
56
- } ) ;
57
- srv . use ( gitAuth . codePath , ( req , res ) => {
58
- res . write ( JSON . stringify ( device ) ) ;
59
- res . end ( ) ;
60
- } ) ;
61
- srv . use ( gitAuth . installationsPath , ( req , res ) => {
62
- res . write ( JSON . stringify ( ghInstall ) ) ;
63
- res . end ( ) ;
64
- } ) ;
67
+ const token = {
68
+ access_token : "" ,
69
+ error : "authorization_pending" ,
70
+ error_description : "" ,
71
+ } ;
72
+ // First we send a result from the API that the token hasn't been
73
+ // authorized yet to ensure the UI reacts properly.
74
+ const sentPending = new Awaiter ( ) ;
75
+ srv . use ( gitAuth . tokenPath , ( req , res ) => {
76
+ res . write ( JSON . stringify ( token ) ) ;
77
+ res . end ( ) ;
78
+ sentPending . done ( ) ;
79
+ } ) ;
65
80
66
- const token = {
67
- access_token : "" ,
68
- error : "authorization_pending" ,
69
- error_description : "" ,
70
- } ;
71
- // First we send a result from the API that the token hasn't been
72
- // authorized yet to ensure the UI reacts properly.
73
- const sentPending = new Awaiter ( ) ;
74
- srv . use ( gitAuth . tokenPath , ( req , res ) => {
75
- res . write ( JSON . stringify ( token ) ) ;
76
- res . end ( ) ;
77
- sentPending . done ( ) ;
81
+ await page . goto ( `/external-auth/${ gitAuth . deviceProvider } ` , {
82
+ waitUntil : "domcontentloaded" ,
83
+ } ) ;
84
+ await page . getByText ( device . user_code ) . isVisible ( ) ;
85
+ await sentPending . wait ( ) ;
86
+ // Update the token to be valid and ensure the UI updates!
87
+ token . error = "" ;
88
+ token . access_token = "hello-world" ;
89
+ await page . waitForSelector ( "text=1 organization authorized" ) ;
78
90
} ) ;
79
91
80
- await page . goto ( `/external-auth/${ gitAuth . deviceProvider } ` , {
81
- waitUntil : "domcontentloaded" ,
92
+ test ( "external auth web" , async ( { page } ) => {
93
+ await page . goto ( `/external-auth/${ gitAuth . webProvider } ` , {
94
+ waitUntil : "domcontentloaded" ,
95
+ } ) ;
96
+ // This endpoint doesn't have the installations URL set intentionally!
97
+ await page . waitForSelector ( "text=You've authenticated with GitHub!" ) ;
82
98
} ) ;
83
- await page . getByText ( device . user_code ) . isVisible ( ) ;
84
- await sentPending . wait ( ) ;
85
- // Update the token to be valid and ensure the UI updates!
86
- token . error = "" ;
87
- token . access_token = "hello-world" ;
88
- await page . waitForSelector ( "text=1 organization authorized" ) ;
89
- } ) ;
90
99
91
- test ( "external auth web" , async ( { page } ) => {
92
- await page . goto ( `/external-auth/${ gitAuth . webProvider } ` , {
93
- waitUntil : "domcontentloaded" ,
100
+ test ( "successful external auth from workspace" , async ( { page } ) => {
101
+ const templateName = await createTemplate (
102
+ page ,
103
+ echoResponsesWithExternalAuth ( [
104
+ { id : gitAuth . webProvider , optional : false } ,
105
+ ] ) ,
106
+ ) ;
107
+
108
+ await createWorkspace ( page , templateName , { useExternalAuth : true } ) ;
94
109
} ) ;
95
- // This endpoint doesn't have the installations URL set intentionally!
96
- await page . waitForSelector ( "text=You've authenticated with GitHub!" ) ;
97
- } ) ;
98
110
99
- test ( "successful external auth from workspace" , async ( { page } ) => {
100
- const templateName = await createTemplate (
101
- page ,
102
- echoResponsesWithExternalAuth ( [
103
- { id : gitAuth . webProvider , optional : false } ,
104
- ] ) ,
105
- ) ;
111
+ const ghUser : Endpoints [ "GET /user" ] [ "response" ] [ "data" ] = {
112
+ login : "kylecarbs" ,
113
+ id : 7122116 ,
114
+ node_id : "MDQ6VXNlcjcxMjIxMTY=" ,
115
+ avatar_url : "https://avatars.githubusercontent.com/u/7122116?v=4" ,
116
+ gravatar_id : "" ,
117
+ url : "https://api.github.com/users/kylecarbs" ,
118
+ html_url : "https://github.com/kylecarbs" ,
119
+ followers_url : "https://api.github.com/users/kylecarbs/followers" ,
120
+ following_url :
121
+ "https://api.github.com/users/kylecarbs/following{/other_user}" ,
122
+ gists_url : "https://api.github.com/users/kylecarbs/gists{/gist_id}" ,
123
+ starred_url :
124
+ "https://api.github.com/users/kylecarbs/starred{/owner}{/repo}" ,
125
+ subscriptions_url : "https://api.github.com/users/kylecarbs/subscriptions" ,
126
+ organizations_url : "https://api.github.com/users/kylecarbs/orgs" ,
127
+ repos_url : "https://api.github.com/users/kylecarbs/repos" ,
128
+ events_url : "https://api.github.com/users/kylecarbs/events{/privacy}" ,
129
+ received_events_url :
130
+ "https://api.github.com/users/kylecarbs/received_events" ,
131
+ type : "User" ,
132
+ site_admin : false ,
133
+ name : "Kyle Carberry" ,
134
+ company : "@coder" ,
135
+ blog : "https://carberry.com" ,
136
+ location : "Austin, TX" ,
137
+ email : "kyle@carberry.com" ,
138
+ hireable : null ,
139
+ bio : "hey there" ,
140
+ twitter_username : "kylecarbs" ,
141
+ public_repos : 52 ,
142
+ public_gists : 9 ,
143
+ followers : 208 ,
144
+ following : 31 ,
145
+ created_at : "2014-04-01T02:24:41Z" ,
146
+ updated_at : "2023-06-26T13:03:09Z" ,
147
+ } ;
106
148
107
- await createWorkspace ( page , templateName , { useExternalAuth : true } ) ;
149
+ const ghInstall : Endpoints [ "GET /user/installations" ] [ "response" ] [ "data" ] = {
150
+ installations : [
151
+ {
152
+ id : 1 ,
153
+ access_tokens_url : "" ,
154
+ account : ghUser ,
155
+ app_id : 1 ,
156
+ app_slug : "coder" ,
157
+ created_at : "2014-04-01T02:24:41Z" ,
158
+ events : [ ] ,
159
+ html_url : "" ,
160
+ permissions : { } ,
161
+ repositories_url : "" ,
162
+ repository_selection : "all" ,
163
+ single_file_name : "" ,
164
+ suspended_at : null ,
165
+ suspended_by : null ,
166
+ target_id : 1 ,
167
+ target_type : "" ,
168
+ updated_at : "2023-06-26T13:03:09Z" ,
169
+ } ,
170
+ ] ,
171
+ total_count : 1 ,
172
+ } ;
108
173
} ) ;
109
-
110
- const ghUser : Endpoints [ "GET /user" ] [ "response" ] [ "data" ] = {
111
- login : "kylecarbs" ,
112
- id : 7122116 ,
113
- node_id : "MDQ6VXNlcjcxMjIxMTY=" ,
114
- avatar_url : "https://avatars.githubusercontent.com/u/7122116?v=4" ,
115
- gravatar_id : "" ,
116
- url : "https://api.github.com/users/kylecarbs" ,
117
- html_url : "https://github.com/kylecarbs" ,
118
- followers_url : "https://api.github.com/users/kylecarbs/followers" ,
119
- following_url :
120
- "https://api.github.com/users/kylecarbs/following{/other_user}" ,
121
- gists_url : "https://api.github.com/users/kylecarbs/gists{/gist_id}" ,
122
- starred_url : "https://api.github.com/users/kylecarbs/starred{/owner}{/repo}" ,
123
- subscriptions_url : "https://api.github.com/users/kylecarbs/subscriptions" ,
124
- organizations_url : "https://api.github.com/users/kylecarbs/orgs" ,
125
- repos_url : "https://api.github.com/users/kylecarbs/repos" ,
126
- events_url : "https://api.github.com/users/kylecarbs/events{/privacy}" ,
127
- received_events_url : "https://api.github.com/users/kylecarbs/received_events" ,
128
- type : "User" ,
129
- site_admin : false ,
130
- name : "Kyle Carberry" ,
131
- company : "@coder" ,
132
- blog : "https://carberry.com" ,
133
- location : "Austin, TX" ,
134
- email : "kyle@carberry.com" ,
135
- hireable : null ,
136
- bio : "hey there" ,
137
- twitter_username : "kylecarbs" ,
138
- public_repos : 52 ,
139
- public_gists : 9 ,
140
- followers : 208 ,
141
- following : 31 ,
142
- created_at : "2014-04-01T02:24:41Z" ,
143
- updated_at : "2023-06-26T13:03:09Z" ,
144
- } ;
145
-
146
- const ghInstall : Endpoints [ "GET /user/installations" ] [ "response" ] [ "data" ] = {
147
- installations : [
148
- {
149
- id : 1 ,
150
- access_tokens_url : "" ,
151
- account : ghUser ,
152
- app_id : 1 ,
153
- app_slug : "coder" ,
154
- created_at : "2014-04-01T02:24:41Z" ,
155
- events : [ ] ,
156
- html_url : "" ,
157
- permissions : { } ,
158
- repositories_url : "" ,
159
- repository_selection : "all" ,
160
- single_file_name : "" ,
161
- suspended_at : null ,
162
- suspended_by : null ,
163
- target_id : 1 ,
164
- target_type : "" ,
165
- updated_at : "2023-06-26T13:03:09Z" ,
166
- } ,
167
- ] ,
168
- total_count : 1 ,
169
- } ;
0 commit comments