@@ -67,10 +67,9 @@ public class LiveTest {
67
67
68
68
@ Test
69
69
public void authenticationOK () throws Throwable {
70
- startSimpleSAML (rr .getUrl ().toString ());
71
- String idpMetadata = readIdPMetadataFromURL ();
72
- rr .then (new AuthenticationOK (idpMetadata ));
70
+ then (() -> new AuthenticationOK (readIdPMetadataFromURL ()));
73
71
}
72
+
74
73
private static class AuthenticationOK implements RealJenkinsRule .Step {
75
74
private final String idpMetadata ;
76
75
AuthenticationOK (String idpMetadata ) {
@@ -87,9 +86,7 @@ public void run(JenkinsRule r) throws Throwable {
87
86
88
87
@ Test
89
88
public void authenticationOKFromURL () throws Throwable {
90
- startSimpleSAML (rr .getUrl ().toString ());
91
- String idpMetadataUrl = createIdPMetadataURL ();
92
- rr .then (new AuthenticationOKFromURL (idpMetadataUrl ));
89
+ then (() -> new AuthenticationOKFromURL (createIdPMetadataURL ()));
93
90
}
94
91
private static class AuthenticationOKFromURL implements RealJenkinsRule .Step {
95
92
private final String idpMetadataUrl ;
@@ -109,9 +106,7 @@ public void run(JenkinsRule r) throws Throwable {
109
106
110
107
@ Test
111
108
public void authenticationOKPostBinding () throws Throwable {
112
- startSimpleSAML (rr .getUrl ().toString ());
113
- String idpMetadata = readIdPMetadataFromURL ();
114
- rr .then (new AuthenticationOKPostBinding (idpMetadata ));
109
+ then (() -> new AuthenticationOKPostBinding (readIdPMetadataFromURL ()));
115
110
}
116
111
private static class AuthenticationOKPostBinding implements RealJenkinsRule .Step {
117
112
private final String idpMetadata ;
@@ -129,9 +124,7 @@ public void run(JenkinsRule r) throws Throwable {
129
124
130
125
@ Test
131
126
public void authenticationFail () throws Throwable {
132
- startSimpleSAML (rr .getUrl ().toString ());
133
- String idpMetadata = readIdPMetadataFromURL ();
134
- rr .then (new AuthenticationFail (idpMetadata ));
127
+ then (() -> new AuthenticationFail (readIdPMetadataFromURL ()));
135
128
}
136
129
private static class AuthenticationFail implements RealJenkinsRule .Step {
137
130
private final String idpMetadata ;
@@ -164,6 +157,21 @@ private String createIdPMetadataURL() {
164
157
return "http://" + samlContainer .getHost () + ":" + samlContainer .getFirstMappedPort () + "/simplesaml/saml2/idp/metadata.php" ;
165
158
}
166
159
160
+ @ FunctionalInterface
161
+ private interface SupplierWithIO <T > {
162
+ T get () throws IOException ;
163
+ }
164
+
165
+ private void then (SupplierWithIO <RealJenkinsRule .Step > provider ) throws Throwable {
166
+ rr .startJenkins ();
167
+ try {
168
+ startSimpleSAML (rr .getUrl ().toString ());
169
+ rr .runRemotely (provider .get ());
170
+ } finally {
171
+ rr .stopJenkins ();
172
+ }
173
+ }
174
+
167
175
private static void configureAuthorization () {
168
176
Jenkins .get ().setAuthorizationStrategy (new MockAuthorizationStrategy ().
169
177
grant (Jenkins .ADMINISTER ).everywhere ().to ("group1" ).
0 commit comments