@@ -17,16 +17,6 @@ func TestWorkspaceAppCors(t *testing.T) {
17
17
regex , err := httpapi .CompileHostnamePattern ("*--apps.dev.coder.com" )
18
18
require .NoError (t , err )
19
19
20
- app := httpapi.ApplicationURL {
21
- AppSlugOrPort : "3000" ,
22
- AgentName : "agent" ,
23
- WorkspaceName : "ws" ,
24
- Username : "user" ,
25
- }
26
-
27
- handler := httpmw .WorkspaceAppCors (regex , app )(http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
28
- rw .WriteHeader (http .StatusNoContent )
29
- }))
30
20
methods := []string {
31
21
http .MethodOptions ,
32
22
http .MethodHead ,
@@ -40,26 +30,62 @@ func TestWorkspaceAppCors(t *testing.T) {
40
30
tests := []struct {
41
31
name string
42
32
origin string
33
+ app httpapi.ApplicationURL
43
34
allowed bool
44
35
}{
45
36
{
46
- name : "Self" ,
47
- origin : "https://3000--agent--ws--user--apps.dev.coder.com" ,
37
+ name : "Self" ,
38
+ origin : "https://3000--agent--ws--user--apps.dev.coder.com" ,
39
+ app : httpapi.ApplicationURL {
40
+ AppSlugOrPort : "3000" ,
41
+ AgentName : "agent" ,
42
+ WorkspaceName : "ws" ,
43
+ Username : "user" ,
44
+ },
48
45
allowed : true ,
49
46
},
50
47
{
51
- name : "SameWorkspace" ,
52
- origin : "https://8000--agent--ws--user--apps.dev.coder.com" ,
48
+ name : "SameWorkspace" ,
49
+ origin : "https://8000--agent--ws--user--apps.dev.coder.com" ,
50
+ app : httpapi.ApplicationURL {
51
+ AppSlugOrPort : "3000" ,
52
+ AgentName : "agent" ,
53
+ WorkspaceName : "ws" ,
54
+ Username : "user" ,
55
+ },
53
56
allowed : true ,
54
57
},
55
58
{
56
- name : "SameUser" ,
57
- origin : "https://8000--agent2--ws2--user--apps.dev.coder.com" ,
59
+ name : "SameUser" ,
60
+ origin : "https://8000--agent2--ws2--user--apps.dev.coder.com" ,
61
+ app : httpapi.ApplicationURL {
62
+ AppSlugOrPort : "3000" ,
63
+ AgentName : "agent" ,
64
+ WorkspaceName : "ws" ,
65
+ Username : "user" ,
66
+ },
58
67
allowed : true ,
59
68
},
60
69
{
61
- name : "DifferentUser" ,
62
- origin : "https://3000--agent--ws--user2--apps.dev.coder.com" ,
70
+ name : "DifferentOriginOwner" ,
71
+ origin : "https://3000--agent--ws--user2--apps.dev.coder.com" ,
72
+ app : httpapi.ApplicationURL {
73
+ AppSlugOrPort : "3000" ,
74
+ AgentName : "agent" ,
75
+ WorkspaceName : "ws" ,
76
+ Username : "user" ,
77
+ },
78
+ allowed : false ,
79
+ },
80
+ {
81
+ name : "DifferentHostOwner" ,
82
+ origin : "https://3000--agent--ws--user--apps.dev.coder.com" ,
83
+ app : httpapi.ApplicationURL {
84
+ AppSlugOrPort : "3000" ,
85
+ AgentName : "agent" ,
86
+ WorkspaceName : "ws" ,
87
+ Username : "user2" ,
88
+ },
63
89
allowed : false ,
64
90
},
65
91
}
@@ -79,6 +105,10 @@ func TestWorkspaceAppCors(t *testing.T) {
79
105
r .Header .Set ("Access-Control-Request-Method" , method )
80
106
}
81
107
108
+ handler := httpmw .WorkspaceAppCors (regex , test .app )(http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
109
+ rw .WriteHeader (http .StatusNoContent )
110
+ }))
111
+
82
112
handler .ServeHTTP (rw , r )
83
113
84
114
if test .allowed {
0 commit comments