@@ -32,7 +32,6 @@ const (
32
32
proxyTestAgentName = "agent-name"
33
33
proxyTestAppNameFake = "test-app-fake"
34
34
proxyTestAppNameOwner = "test-app-owner"
35
- proxyTestAppNameTemplate = "test-app-template"
36
35
proxyTestAppNameAuthenticated = "test-app-authenticated"
37
36
proxyTestAppNamePublic = "test-app-public"
38
37
proxyTestAppQuery = "query=true"
@@ -134,11 +133,6 @@ func setupProxyTest(t *testing.T, workspaceMutators ...func(*codersdk.CreateWork
134
133
SharingLevel : proto .AppSharingLevel_OWNER ,
135
134
Url : appURL ,
136
135
},
137
- {
138
- Name : proxyTestAppNameTemplate ,
139
- SharingLevel : proto .AppSharingLevel_TEMPLATE ,
140
- Url : appURL ,
141
- },
142
136
{
143
137
Name : proxyTestAppNameAuthenticated ,
144
138
SharingLevel : proto .AppSharingLevel_AUTHENTICATED ,
@@ -736,11 +730,11 @@ func TestWorkspaceAppsProxySubdomain(t *testing.T) {
736
730
func TestAppSharing (t * testing.T ) {
737
731
t .Parallel ()
738
732
739
- setup := func (t * testing.T ) (workspace codersdk.Workspace , agnt codersdk.WorkspaceAgent , user codersdk.User , client * codersdk.Client , clientWithTemplateAccess * codersdk. Client , clientWithNoTemplateAccess * codersdk.Client , clientWithNoAuth * codersdk.Client ) {
733
+ setup := func (t * testing.T ) (workspace codersdk.Workspace , agnt codersdk.WorkspaceAgent , user codersdk.User , client * codersdk.Client , clientInOtherOrg * codersdk.Client , clientWithNoAuth * codersdk.Client ) {
740
734
//nolint:gosec
741
735
const password = "password"
742
736
743
- client , firstUser , workspace , _ : = setupProxyTest (t )
737
+ client , _ , workspace , _ = setupProxyTest (t )
744
738
745
739
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
746
740
t .Cleanup (cancel )
@@ -756,7 +750,6 @@ func TestAppSharing(t *testing.T) {
756
750
expected := map [string ]codersdk.WorkspaceAppSharingLevel {
757
751
proxyTestAppNameFake : codersdk .WorkspaceAppSharingLevelOwner ,
758
752
proxyTestAppNameOwner : codersdk .WorkspaceAppSharingLevelOwner ,
759
- proxyTestAppNameTemplate : codersdk .WorkspaceAppSharingLevelTemplate ,
760
753
proxyTestAppNameAuthenticated : codersdk .WorkspaceAppSharingLevelAuthenticated ,
761
754
proxyTestAppNamePublic : codersdk .WorkspaceAppSharingLevelPublic ,
762
755
}
@@ -765,66 +758,37 @@ func TestAppSharing(t *testing.T) {
765
758
}
766
759
require .Equal (t , expected , found , "apps have incorrect sharing levels" )
767
760
768
- // Create a user in the same org (should be able to read the template).
769
- userWithTemplateAccess , err := client .CreateUser (ctx , codersdk.CreateUserRequest {
770
-
771
- Username : "template-access" ,
772
- Password : password ,
773
- OrganizationID : firstUser .OrganizationID ,
774
- })
775
- require .NoError (t , err )
776
-
777
- clientWithTemplateAccess = codersdk .New (client .URL )
778
- loginRes , err := clientWithTemplateAccess .LoginWithPassword (ctx , codersdk.LoginWithPasswordRequest {
779
- Email : userWithTemplateAccess .Email ,
780
- Password : password ,
781
- })
782
- require .NoError (t , err )
783
- clientWithTemplateAccess .SessionToken = loginRes .SessionToken
784
- clientWithTemplateAccess .HTTPClient .CheckRedirect = func (req * http.Request , via []* http.Request ) error {
785
- return http .ErrUseLastResponse
786
- }
787
-
788
- // Double check that the user can read the template.
789
- _ , err = clientWithTemplateAccess .Template (ctx , workspace .TemplateID )
790
- require .NoError (t , err )
791
-
792
- // Create a user in a different org (should not be able to read the
793
- // template).
794
- differentOrg , err := client .CreateOrganization (ctx , codersdk.CreateOrganizationRequest {
761
+ // Create a user in a different org.
762
+ otherOrg , err := client .CreateOrganization (ctx , codersdk.CreateOrganizationRequest {
795
763
Name : "a-different-org" ,
796
764
})
797
765
require .NoError (t , err )
798
- userWithNoTemplateAccess , err := client .CreateUser (ctx , codersdk.CreateUserRequest {
766
+ userInOtherOrg , err := client .CreateUser (ctx , codersdk.CreateUserRequest {
799
767
800
768
Username : "no-template-access" ,
801
769
Password : password ,
802
- OrganizationID : differentOrg .ID ,
770
+ OrganizationID : otherOrg .ID ,
803
771
})
804
772
require .NoError (t , err )
805
773
806
- clientWithNoTemplateAccess = codersdk .New (client .URL )
807
- loginRes , err = clientWithNoTemplateAccess .LoginWithPassword (ctx , codersdk.LoginWithPasswordRequest {
808
- Email : userWithNoTemplateAccess .Email ,
774
+ clientInOtherOrg = codersdk .New (client .URL )
775
+ loginRes , err := clientInOtherOrg .LoginWithPassword (ctx , codersdk.LoginWithPasswordRequest {
776
+ Email : userInOtherOrg .Email ,
809
777
Password : password ,
810
778
})
811
779
require .NoError (t , err )
812
- clientWithNoTemplateAccess .SessionToken = loginRes .SessionToken
813
- clientWithNoTemplateAccess .HTTPClient .CheckRedirect = func (req * http.Request , via []* http.Request ) error {
780
+ clientInOtherOrg .SessionToken = loginRes .SessionToken
781
+ clientInOtherOrg .HTTPClient .CheckRedirect = func (req * http.Request , via []* http.Request ) error {
814
782
return http .ErrUseLastResponse
815
783
}
816
784
817
- // Double check that the user cannot read the template.
818
- _ , err = clientWithNoTemplateAccess .Template (ctx , workspace .TemplateID )
819
- require .Error (t , err )
820
-
821
785
// Create an unauthenticated codersdk client.
822
786
clientWithNoAuth = codersdk .New (client .URL )
823
787
clientWithNoAuth .HTTPClient .CheckRedirect = func (req * http.Request , via []* http.Request ) error {
824
788
return http .ErrUseLastResponse
825
789
}
826
790
827
- return workspace , agnt , user , client , clientWithTemplateAccess , clientWithNoTemplateAccess , clientWithNoAuth
791
+ return workspace , agnt , user , client , clientInOtherOrg , clientWithNoAuth
828
792
}
829
793
830
794
verifyAccess := func (t * testing.T , username , workspaceName , agentName , appName string , client * codersdk.Client , shouldHaveAccess , shouldRedirectToLogin bool ) {
@@ -884,50 +848,30 @@ func TestAppSharing(t *testing.T) {
884
848
t .Run ("Level" , func (t * testing.T ) {
885
849
t .Parallel ()
886
850
887
- workspace , agent , user , client , clientWithTemplateAccess , clientWithNoTemplateAccess , clientWithNoAuth := setup (t )
851
+ workspace , agent , user , client , clientInOtherOrg , clientWithNoAuth := setup (t )
888
852
889
853
t .Run ("Owner" , func (t * testing.T ) {
890
854
t .Parallel ()
891
855
892
856
// Owner should be able to access their own workspace.
893
857
verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameOwner , client , true , false )
894
858
895
- // User with or without template access should not have access to a
896
- // workspace that they do not own.
897
- verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameOwner , clientWithTemplateAccess , false , false )
898
- verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameOwner , clientWithNoTemplateAccess , false , false )
859
+ // Authenticated users should not have access to a workspace that
860
+ // they do not own.
861
+ verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameOwner , clientInOtherOrg , false , false )
899
862
900
863
// Unauthenticated user should not have any access.
901
864
verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameOwner , clientWithNoAuth , false , true )
902
865
})
903
866
904
- t .Run ("Template" , func (t * testing.T ) {
905
- t .Parallel ()
906
-
907
- // Owner should be able to access their own workspace.
908
- verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameTemplate , client , true , false )
909
-
910
- // User with template access should be able to access the workspace.
911
- verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameTemplate , clientWithTemplateAccess , true , false )
912
-
913
- // User without template access should not have access to a workspace
914
- // that they do not own.
915
- verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameTemplate , clientWithNoTemplateAccess , false , false )
916
-
917
- // Unauthenticated user should not have any access.
918
- verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameTemplate , clientWithNoAuth , false , true )
919
- })
920
-
921
867
t .Run ("Authenticated" , func (t * testing.T ) {
922
868
t .Parallel ()
923
869
924
870
// Owner should be able to access their own workspace.
925
871
verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameAuthenticated , client , true , false )
926
872
927
- // User with or without template access should be able to access the
928
- // workspace.
929
- verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameAuthenticated , clientWithTemplateAccess , true , false )
930
- verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameAuthenticated , clientWithNoTemplateAccess , true , false )
873
+ // Authenticated users should be able to access the workspace.
874
+ verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameAuthenticated , clientInOtherOrg , true , false )
931
875
932
876
// Unauthenticated user should not have any access.
933
877
verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNameAuthenticated , clientWithNoAuth , false , true )
@@ -939,10 +883,8 @@ func TestAppSharing(t *testing.T) {
939
883
// Owner should be able to access their own workspace.
940
884
verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNamePublic , client , true , false )
941
885
942
- // User with or without template access should be able to access the
943
- // workspace.
944
- verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNamePublic , clientWithTemplateAccess , true , false )
945
- verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNamePublic , clientWithNoTemplateAccess , true , false )
886
+ // Authenticated users should be able to access the workspace.
887
+ verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNamePublic , clientInOtherOrg , true , false )
946
888
947
889
// Unauthenticated user should be able to access the workspace.
948
890
verifyAccess (t , user .Username , workspace .Name , agent .Name , proxyTestAppNamePublic , clientWithNoAuth , true , false )
0 commit comments