@@ -17,16 +17,6 @@ func TestWorkspaceAppCors(t *testing.T) {
1717regex ,err := httpapi .CompileHostnamePattern ("*--apps.dev.coder.com" )
1818require .NoError (t ,err )
1919
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- }))
3020methods := []string {
3121http .MethodOptions ,
3222http .MethodHead ,
@@ -40,26 +30,62 @@ func TestWorkspaceAppCors(t *testing.T) {
4030tests := []struct {
4131name string
4232origin string
33+ app httpapi.ApplicationURL
4334allowed bool
4435}{
4536{
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+ },
4845allowed :true ,
4946},
5047{
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+ },
5356allowed :true ,
5457},
5558{
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+ },
5867allowed :true ,
5968},
6069{
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+ },
6389allowed :false ,
6490},
6591}
@@ -79,6 +105,10 @@ func TestWorkspaceAppCors(t *testing.T) {
79105r .Header .Set ("Access-Control-Request-Method" ,method )
80106}
81107
108+ handler := httpmw .WorkspaceAppCors (regex ,test .app )(http .HandlerFunc (func (rw http.ResponseWriter ,r * http.Request ) {
109+ rw .WriteHeader (http .StatusNoContent )
110+ }))
111+
82112handler .ServeHTTP (rw ,r )
83113
84114if test .allowed {