DaanHoogland commented on code in PR #6457:
URL: https://github.com/apache/cloudstack/pull/6457#discussion_r912853480
##########
plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAMLUtilsTest.java:
##########
@@ -60,6 +64,68 @@ public void testBuildAuthnRequestObject() throws Exception {
assertEquals(req.getIssuer().getValue(), spId);
}
+ @Test
+ public void testBuildAuthnRequestUrlWithoutQueryParam() throws Exception {
+ String urlScheme = "http";
+
+ String spDomain = "sp.domain.example";
+ String spUrl = urlScheme + "://" + spDomain;
+ String spId = "serviceProviderId";
+
+ String idpDomain = "idp.domain.example";
+ String idpUrl = urlScheme + "://" + idpDomain;
+ String idpId = "identityProviderId";
+
+ String authnId = SAMLUtils.generateSecureRandomId();
+
+ SAMLProviderMetadata spMetadata = new SAMLProviderMetadata();
+ spMetadata.setEntityId(spId);
+ spMetadata.setSsoUrl(spUrl);
+
+ SAMLProviderMetadata idpMetadata = new SAMLProviderMetadata();
+ idpMetadata.setSsoUrl(idpUrl);
+ idpMetadata.setEntityId(idpId);
+
+ URI redirectUrl = new URI(SAMLUtils.buildAuthnRequestUrl(authnId,
spMetadata, idpMetadata, SAML2AuthManager.SAMLSignatureAlgorithm.value()));
+ assertThat(redirectUrl).hasScheme(urlScheme);
+ assertEquals(urlScheme, redirectUrl.getScheme());
+ assertThat(redirectUrl).hasHost(idpDomain);
+ assertEquals(idpDomain, redirectUrl.getHost());
+ assertThat(redirectUrl).hasParameter("SAMLRequest");
+ }
+
+ @Test
+ public void testBuildAuthnRequestUrlWithQueryParam() throws Exception {
+ String urlScheme = "http";
+
+ String spDomain = "sp.domain.example";
+ String spUrl = urlScheme + "://" + spDomain;
+ String spId = "cloudstack";
+
+ String idpDomain = "idp.domain.example";
+ String idpQueryParam = "idpid=CX1298373";
+ String idpUrl = urlScheme + "://" + idpDomain + "?" + idpQueryParam;
+ String idpId = "identityProviderId";
+
+ String authnId = SAMLUtils.generateSecureRandomId();
+
+ SAMLProviderMetadata spMetadata = new SAMLProviderMetadata();
+ spMetadata.setEntityId(spId);
+ spMetadata.setSsoUrl(spUrl);
+
+ SAMLProviderMetadata idpMetadata = new SAMLProviderMetadata();
+ idpMetadata.setSsoUrl(idpUrl);
+ idpMetadata.setEntityId(idpId);
+
+ URI redirectUrl = new URI(SAMLUtils.buildAuthnRequestUrl(authnId,
spMetadata, idpMetadata, SAML2AuthManager.SAMLSignatureAlgorithm.value()));
+ assertThat(redirectUrl).hasScheme(urlScheme);
+ assertEquals(urlScheme, redirectUrl.getScheme());
+ assertThat(redirectUrl).hasHost(idpDomain);
+ assertEquals(idpDomain, redirectUrl.getHost());
+ assertThat(redirectUrl).hasParameter("idpid");
+ assertThat(redirectUrl).hasParameter("SAMLRequest");
Review Comment:
```suggestion
assertThat(redirectUrl).hasScheme(urlScheme).hasHost(idpDomain).hasParameter("idpid").hasParameter("SAMLRequest");
assertEquals(urlScheme, redirectUrl.getScheme());
assertEquals(idpDomain, redirectUrl.getHost());
```
##########
plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAMLUtilsTest.java:
##########
@@ -60,6 +62,32 @@ public void testBuildAuthnRequestObject() throws Exception {
assertEquals(req.getIssuer().getValue(), spId);
}
+ @Test
+ public void testBuildAuthnRequestUrlWithoutQueryParam() throws Exception {
+ String consumerUrl = "http://someurl.com";
+ String idpUrl = "http://idp.domain.example";
+ String spId = "cloudstack";
+ String authnId = SAMLUtils.generateSecureRandomId();
+ DefaultBootstrap.bootstrap();
+ AuthnRequest req = SAMLUtils.buildAuthnRequestObject(authnId, spId,
idpUrl, consumerUrl);
+ String appendOperator = idpUrl.contains("?") ? "&" : "?";
+ String redirectUrl = idpUrl + appendOperator +
SAMLUtils.generateSAMLRequestSignature("SAMLRequest=" +
SAMLUtils.encodeSAMLRequest(req), null,
SAML2AuthManager.SAMLSignatureAlgorithm.value());
+ assertEquals(redirectUrl, idpUrl + "?" +
SAMLUtils.generateSAMLRequestSignature("SAMLRequest=" +
SAMLUtils.encodeSAMLRequest(req), null,
SAML2AuthManager.SAMLSignatureAlgorithm.value()));
Review Comment:
your tests look much cleaner now @Luis-3M , and they seem to actually test
the return of the production method, thanks a lot. We can always improve later
if we feel we should assert something else.
##########
plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAMLUtilsTest.java:
##########
@@ -60,6 +64,68 @@ public void testBuildAuthnRequestObject() throws Exception {
assertEquals(req.getIssuer().getValue(), spId);
}
+ @Test
+ public void testBuildAuthnRequestUrlWithoutQueryParam() throws Exception {
+ String urlScheme = "http";
+
+ String spDomain = "sp.domain.example";
+ String spUrl = urlScheme + "://" + spDomain;
+ String spId = "serviceProviderId";
+
+ String idpDomain = "idp.domain.example";
+ String idpUrl = urlScheme + "://" + idpDomain;
+ String idpId = "identityProviderId";
+
+ String authnId = SAMLUtils.generateSecureRandomId();
+
+ SAMLProviderMetadata spMetadata = new SAMLProviderMetadata();
+ spMetadata.setEntityId(spId);
+ spMetadata.setSsoUrl(spUrl);
+
+ SAMLProviderMetadata idpMetadata = new SAMLProviderMetadata();
+ idpMetadata.setSsoUrl(idpUrl);
+ idpMetadata.setEntityId(idpId);
+
+ URI redirectUrl = new URI(SAMLUtils.buildAuthnRequestUrl(authnId,
spMetadata, idpMetadata, SAML2AuthManager.SAMLSignatureAlgorithm.value()));
+ assertThat(redirectUrl).hasScheme(urlScheme);
+ assertEquals(urlScheme, redirectUrl.getScheme());
+ assertThat(redirectUrl).hasHost(idpDomain);
+ assertEquals(idpDomain, redirectUrl.getHost());
+ assertThat(redirectUrl).hasParameter("SAMLRequest");
Review Comment:
```suggestion
assertThat(redirectUrl).hasScheme(urlScheme).hasHost(idpDomain).hasParameter("SAMLRequest");
assertEquals(urlScheme, redirectUrl.getScheme());
assertEquals(idpDomain, redirectUrl.getHost());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]