Skip to content

Commit

Permalink
Updated IdentityZoneEndpointDocs with Branding information
Browse files Browse the repository at this point in the history
[#117107815] https://www.pivotaltracker.com/story/show/117107815

Signed-off-by: Priyata Agrawal <pagrawal@pivotal.io>
  • Loading branch information
staylor14 authored and Priyata25 committed Aug 12, 2016
1 parent 5468891 commit 6fa0ce4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 17 deletions.
Expand Up @@ -294,36 +294,33 @@ public void testDefaultLogo() throws Exception {

@Test
public void testCustomLogo() throws Exception {
BrandingInformation branding = new BrandingInformation();
branding.setProductLogo("/bASe/64+");
identityZoneConfiguration.setBranding(branding);
setZoneConfiguration(identityZoneConfiguration);
setZoneFavIconAndProductLogo(null, "/bASe/64+");

getMockMvc().perform(get("/login"))
.andExpect(content().string(allOf(containsString("url(data:image/png;base64,/bASe/64+)"), not(containsString("url(/uaa/resources/oss/images/product-logo.png)")))));
}

@Test
public void testCustomFavIcon() throws Exception {
setZoneFavIcon("/sM4lL==");
setZoneFavIconAndProductLogo("/sM4lL==", null);

getMockMvc().perform(get("/login"))
.andExpect(content().string(allOf(containsString("<link href=\"data:image/png;base64,/sM4lL==\" rel=\"shortcut icon\""), not(containsString("square-logo.png")))));
}

@Test
public void testCustomFavIcon_With_LineBreaks() throws Exception {
setZoneFavIcon("/sM4\n\nlL==");
mockEnvironment.setProperty("login.branding.productLogo", "/sM4\n\nlL==");
setZoneFavIconAndProductLogo("/sM4\n\nlL==", "/sM4\n\nlL==");

getMockMvc().perform(get("/login"))
.andExpect(content().string(allOf(containsString("<link href=\"data:image/png;base64,/sM4\n\nlL==\" rel=\"shortcut icon\""), not(containsString("square-logo.png")))))
.andExpect(content().string(allOf(containsString("style>.header-image {background-image: url(data:image/png;base64,/sM4lL==);}</style>"), not(containsString("product-logo.png")))));
}

private void setZoneFavIcon(String favIcon) {
private void setZoneFavIconAndProductLogo(String favIcon, String productLogo) {
BrandingInformation branding = new BrandingInformation();
branding.setSquareLogo(favIcon);
branding.setProductLogo(productLogo);
identityZoneConfiguration.setBranding(branding);
setZoneConfiguration(identityZoneConfiguration);
}
Expand Down
Expand Up @@ -3,7 +3,9 @@
import org.cloudfoundry.identity.uaa.mock.InjectedMockContextTest;
import org.cloudfoundry.identity.uaa.test.TestClient;
import org.cloudfoundry.identity.uaa.util.JsonUtils;
import org.cloudfoundry.identity.uaa.zone.BrandingInformation;
import org.cloudfoundry.identity.uaa.zone.IdentityZone;
import org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -68,6 +70,12 @@ public class IdentityZoneEndpointDocs extends InjectedMockContextTest {
private static final String PROMPTS_TYPE_DESC = "What kind of field this is (e.g. text or password)";
private static final String PROMPTS_TEXT_DESC = "Actual text displayed on prompt for field";
private static final String IDP_DISCOVERY_ENABLED_FLAG = "IDP Discovery should be set to true if you have configured more than one identity provider for UAA. The discovery relies on email domain being set for each additional provider";
private static final String BRANDING_COMPANY_NAME_DESC = "This name is used on the UAA Pages and in account management related communication in UAA";
private static final String BRANDING_PRODUCT_LOGO_DESC = "This is a base64 encoded PNG image which will be used as the logo on all UAA pages like Login, Sign Up etc.";
private static final String BRANDING_SQUARE_LOGO_DESC = "This is a base64 encoded PNG image which will be used as the favicon for the UAA pages";
private static final String BRANDING_FOOTER_LEGAL_TEXT_DESC = "This text appears on the footer of all UAA pages";
private static final String BRANDING_FOOTER_LINKS_DESC = "These links appear on the footer of all UAA pages. You may choose to add multiple urls for things like Support, Terms of Service etc.";

private TestClient testClient;

@Before
Expand All @@ -93,6 +101,8 @@ public void createIdentityZone() throws Exception {
Map<String, String> keys = new HashMap<>();
keys.put("exampleKeyId", "s1gNiNg.K3y/t3XT");
identityZone.getConfig().getTokenPolicy().setKeys(keys);
IdentityZoneConfiguration brandingConfig = setBranding(identityZone.getConfig());
identityZone.setConfig(brandingConfig);

FieldDescriptor[] fieldDescriptors = {
fieldWithPath("id").description(ID_DESC).attributes(key("constraints").value("Optional")),
Expand Down Expand Up @@ -131,6 +141,12 @@ public void createIdentityZone() throws Exception {

fieldWithPath("config.idpDiscoveryEnabled").description(IDP_DISCOVERY_ENABLED_FLAG).attributes(key("constraints").value("Optional")),

fieldWithPath("config.branding.companyName").description(BRANDING_COMPANY_NAME_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("config.branding.productLogo").description(BRANDING_PRODUCT_LOGO_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("config.branding.squareLogo").description(BRANDING_SQUARE_LOGO_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("config.branding.footerLegalText").description(BRANDING_FOOTER_LEGAL_TEXT_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("config.branding.footerLinks").description(BRANDING_FOOTER_LINKS_DESC).attributes(key("constraints").value("Optional")),

fieldWithPath("created").ignored(),
fieldWithPath("last_modified").ignored()
};
Expand All @@ -142,12 +158,12 @@ public void createIdentityZone() throws Exception {
.content(JsonUtils.writeValueAsString(identityZone)))
.andExpect(status().is(HttpStatus.CREATED.value()))
.andDo(document("{ClassName}/{methodName}",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
requestHeaders(
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
requestHeaders(
headerWithName("Authorization").description("Bearer token containing `zones.write` or `zones.<zone id>.admin`")
),
requestFields(fieldDescriptors),
),
requestFields(fieldDescriptors),
getResponseFields()
));
}
Expand Down Expand Up @@ -228,6 +244,12 @@ public void getAllIdentityZones() throws Exception {

fieldWithPath("[].config.idpDiscoveryEnabled").description(IDP_DISCOVERY_ENABLED_FLAG),

fieldWithPath("[].config.branding.companyName").description(BRANDING_COMPANY_NAME_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("[].config.branding.productLogo").description(BRANDING_PRODUCT_LOGO_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("[].config.branding.squareLogo").description(BRANDING_SQUARE_LOGO_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("[].config.branding.footerLegalText").description(BRANDING_FOOTER_LEGAL_TEXT_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("[].config.branding.footerLinks").description(BRANDING_FOOTER_LINKS_DESC).attributes(key("constraints").value("Optional")),

fieldWithPath("[].created").ignored(),
fieldWithPath("[].last_modified").ignored()
);
Expand Down Expand Up @@ -262,6 +284,8 @@ public void updateIdentityZone() throws Exception {
Map<String, String> keys = new HashMap<>();
keys.put("updatedKeyId", "upD4t3d.s1gNiNg.K3y/t3XT");
updatedIdentityZone.getConfig().getTokenPolicy().setKeys(keys);
IdentityZoneConfiguration brandingConfig = setBranding(updatedIdentityZone.getConfig());
updatedIdentityZone.setConfig(brandingConfig);

Snippet requestFields = requestFields(
fieldWithPath("subdomain").description(SUBDOMAIN_DESC).attributes(key("constraints").value("Required")),
Expand Down Expand Up @@ -299,6 +323,12 @@ public void updateIdentityZone() throws Exception {

fieldWithPath("config.idpDiscoveryEnabled").description(IDP_DISCOVERY_ENABLED_FLAG).attributes(key("constraints").value("Optional")),

fieldWithPath("config.branding.companyName").description(BRANDING_COMPANY_NAME_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("config.branding.productLogo").description(BRANDING_PRODUCT_LOGO_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("config.branding.squareLogo").description(BRANDING_SQUARE_LOGO_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("config.branding.footerLegalText").description(BRANDING_FOOTER_LEGAL_TEXT_DESC).attributes(key("constraints").value("Optional")),
fieldWithPath("config.branding.footerLinks").description(BRANDING_FOOTER_LINKS_DESC).attributes(key("constraints").value("Optional")),

fieldWithPath("created").ignored(),
fieldWithPath("last_modified").ignored()
);
Expand Down Expand Up @@ -356,10 +386,14 @@ private void createIdentityZoneHelper(String id) throws Exception {
"identitysecret",
"zones.write");

Map<String, String> identityZone = new HashMap<>();
identityZone.put("id", id);
identityZone.put("subdomain", StringUtils.hasText(id) ? id : new RandomValueStringGenerator().generate());
identityZone.put("name", "The Twiglet Zone");
IdentityZone identityZone = new IdentityZone();
identityZone.setId(id);
identityZone.setSubdomain(StringUtils.hasText(id) ? id : new RandomValueStringGenerator().generate());
identityZone.setName("The Twiglet Zone");

IdentityZoneConfiguration brandingConfig = setBranding(identityZone.getConfig());
identityZone.setConfig(brandingConfig);


getMockMvc().perform(
post("/identity-zones")
Expand Down Expand Up @@ -406,9 +440,25 @@ private Snippet getResponseFields() {
fieldWithPath("config.prompts[].text").description(PROMPTS_TEXT_DESC),

fieldWithPath("config.idpDiscoveryEnabled").description(IDP_DISCOVERY_ENABLED_FLAG),
fieldWithPath("config.branding.companyName").description(BRANDING_COMPANY_NAME_DESC),
fieldWithPath("config.branding.productLogo").description(BRANDING_PRODUCT_LOGO_DESC),
fieldWithPath("config.branding.squareLogo").description(BRANDING_SQUARE_LOGO_DESC),
fieldWithPath("config.branding.footerLegalText").description(BRANDING_FOOTER_LEGAL_TEXT_DESC),
fieldWithPath("config.branding.footerLinks").description(BRANDING_FOOTER_LINKS_DESC),

fieldWithPath("created").ignored(),
fieldWithPath("last_modified").ignored()
);
}

private IdentityZoneConfiguration setBranding(IdentityZoneConfiguration config){
BrandingInformation branding = new BrandingInformation();
branding.setCompanyName("Test Company");
branding.setProductLogo("VGVzdFByb2R1Y3RMb2dv");
branding.setSquareLogo("VGVzdFNxdWFyZUxvZ28=");
branding.setFooterLegalText("Test footer legal text");
branding.setFooterLinks(new HashMap<>());
config.setBranding(branding);
return config;
}
}

0 comments on commit 6fa0ce4

Please sign in to comment.