9
9
import hudson .model .User ;
10
10
import hudson .security .ACL ;
11
11
import hudson .security .ACLContext ;
12
+ import hudson .util .FormValidation ;
12
13
import hudson .util .ListBoxModel ;
13
14
import java .io .IOException ;
14
15
import java .net .HttpURLConnection ;
@@ -35,6 +36,7 @@ public class Security2033Test {
35
36
36
37
private static final String PROJECT_NAME = "p" ;
37
38
private static final String NOT_AUTHORIZED_USER = "userNoPermission" ;
39
+ private static final String NO_ITEM_READ_USER = "userNoReadPermission" ;
38
40
private static final String SERVER_URL = "server.url" ;
39
41
40
42
@ Rule
@@ -95,6 +97,17 @@ public void doCheckCredentialsIdSCMSourceWhenUserWithoutCredentialsViewPermissio
95
97
}
96
98
}
97
99
100
+ @ Issue ("SECURITY-2033" )
101
+ @ Test
102
+ public void doCheckServerUrlWhenUserWithoutPermissionThenReturnForbiddenMessage () {
103
+ ((MockAuthorizationStrategy ) j .jenkins .getAuthorizationStrategy ())
104
+ .grant (Jenkins .READ , Item .READ ).everywhere ().to (NOT_AUTHORIZED_USER );
105
+ try (ACLContext aclContext = ACL .as (User .getOrCreateByIdOrFullName (NO_ITEM_READ_USER ))) {
106
+ FormValidation formValidation = BitbucketSCMSource .DescriptorImpl .doCheckServerUrl (pr , SERVER_URL );
107
+ assertThat (formValidation .getMessage (), is ("Unauthorized to validate Server URL" ));
108
+ }
109
+ }
110
+
98
111
@ Issue ("SECURITY-2033" )
99
112
@ Test
100
113
public void doFillServerUrlItemsSCMNavigatorWhenUserWithoutPermissionThenReturnEmptyList () {
@@ -115,17 +128,6 @@ public void doFillServerUrlItemsSCMSourceWhenUserWithoutPermissionThenReturnEmpt
115
128
}
116
129
}
117
130
118
- @ Issue ("SECURITY-2033" )
119
- @ Test
120
- public void doCheckServerUrlWhenUserWithoutPermissionThenReturnForbiddenStatus () {
121
- try (ACLContext aclContext = ACL .as (User .getOrCreateByIdOrFullName (NOT_AUTHORIZED_USER ))) {
122
- BitbucketSCMSource .DescriptorImpl .doCheckServerUrl (pr , SERVER_URL );
123
- fail ("Should fail with AccessDeniedException2" );
124
- } catch (Exception accessDeniedException2 ) {
125
- assertThat (accessDeniedException2 .getMessage (), is (NOT_AUTHORIZED_USER + " is missing the Job/Configure permission" ));
126
- }
127
- }
128
-
129
131
@ Issue ("SECURITY-2033" )
130
132
@ Test
131
133
public void doShowStatsWhenUserWithoutAdminPermissionThenReturnForbiddenStatus () {
0 commit comments