From bf4999d172162dc45ff2e848ee8498b141261328 Mon Sep 17 00:00:00 2001 From: Filip Hanik Date: Mon, 14 Nov 2016 17:07:34 -0800 Subject: [PATCH] Remove logging of non essential data [#134322559] https://www.pivotaltracker.com/story/show/134322559 --- .../uaa/audit/event/EntityDeletedEvent.java | 18 +++- .../event/IdentityProviderModifiedEvent.java | 18 +++- .../zone/event/IdentityZoneModifiedEvent.java | 14 ++- .../event/ServiceProviderModifiedEvent.java | 15 ++-- .../audit/event/EntityDeletedEventTest.java | 57 ++++++++++++ .../IdentityProviderModifiedEventTest.java | 87 +++++++++++++++++++ .../event/IdentityZoneModifiedEventTest.java | 68 +++++++++++++++ .../ServiceProviderModifiedEventTest.java | 63 ++++++++++++++ .../IdentityZoneEndpointsMockMvcTests.java | 5 +- 9 files changed, 329 insertions(+), 16 deletions(-) create mode 100644 server/src/test/java/org/cloudfoundry/identity/uaa/audit/event/EntityDeletedEventTest.java create mode 100644 server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/IdentityProviderModifiedEventTest.java create mode 100644 server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/IdentityZoneModifiedEventTest.java create mode 100644 server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEventTest.java diff --git a/server/src/main/java/org/cloudfoundry/identity/uaa/audit/event/EntityDeletedEvent.java b/server/src/main/java/org/cloudfoundry/identity/uaa/audit/event/EntityDeletedEvent.java index db5649edd81..08f191a2aa9 100644 --- a/server/src/main/java/org/cloudfoundry/identity/uaa/audit/event/EntityDeletedEvent.java +++ b/server/src/main/java/org/cloudfoundry/identity/uaa/audit/event/EntityDeletedEvent.java @@ -17,11 +17,15 @@ import org.cloudfoundry.identity.uaa.audit.AuditEvent; import org.cloudfoundry.identity.uaa.audit.AuditEventType; -import org.cloudfoundry.identity.uaa.util.JsonUtils; import org.springframework.security.core.Authentication; +import org.springframework.util.ReflectionUtils; + +import java.lang.reflect.Method; public class EntityDeletedEvent extends AbstractUaaEvent { + protected static final String dataFormat = "Class:%s; ID:%s"; + public EntityDeletedEvent(T deleted, Authentication authentication) { super(deleted, authentication); } @@ -32,6 +36,16 @@ public T getDeleted() { @Override public AuditEvent getAuditEvent() { - return createAuditRecord(getAuthentication().getName(), AuditEventType.EntityDeletedEvent, getOrigin(getAuthentication()), JsonUtils.writeValueAsString(source)); + return createAuditRecord( + getAuthentication().getName(), + AuditEventType.EntityDeletedEvent, + getOrigin(getAuthentication()), + String.format(dataFormat, source.getClass().getName(), getObjectId()) + ); + } + + public String getObjectId() { + Method m = ReflectionUtils.findMethod(source.getClass(), "getId"); + return m!=null ? (String)ReflectionUtils.invokeMethod(m, source) : String.valueOf(System.identityHashCode(source)); } } diff --git a/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/IdentityProviderModifiedEvent.java b/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/IdentityProviderModifiedEvent.java index ef0d51e078a..41b3563ed37 100644 --- a/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/IdentityProviderModifiedEvent.java +++ b/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/IdentityProviderModifiedEvent.java @@ -16,7 +16,6 @@ import org.cloudfoundry.identity.uaa.audit.AuditEvent; import org.cloudfoundry.identity.uaa.audit.AuditEventType; import org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent; -import org.cloudfoundry.identity.uaa.util.JsonUtils; import org.cloudfoundry.identity.uaa.provider.IdentityProvider; import org.springframework.security.core.Authentication; @@ -26,6 +25,8 @@ public class IdentityProviderModifiedEvent extends AbstractUaaEvent { private AuditEventType eventType; + protected static final String dataFormat = "id=%s; type=%s; origin=%s; zone=%s"; + public IdentityProviderModifiedEvent(IdentityProvider identityProvider, Authentication authentication, AuditEventType type) { super(identityProvider, authentication); eventType = type; @@ -33,13 +34,22 @@ public IdentityProviderModifiedEvent(IdentityProvider identityProvider, Authenti @Override public AuditEvent getAuditEvent() { - return createAuditRecord(getSource().toString(), eventType, getOrigin(getAuthentication()), JsonUtils.writeValueAsString(source)); + IdentityProvider provider = (IdentityProvider)source; + return createAuditRecord(getSource().toString(), + eventType, + getOrigin(getAuthentication()), + String.format(IdentityProviderModifiedEvent.dataFormat, + provider.getId(), + provider.getType(), + provider.getOriginKey(), + provider.getIdentityZoneId()) + ); } - + public static IdentityProviderModifiedEvent identityProviderCreated(IdentityProvider identityProvider) { return new IdentityProviderModifiedEvent(identityProvider, getContextAuthentication(), AuditEventType.IdentityProviderCreatedEvent); } - + public static IdentityProviderModifiedEvent identityProviderModified(IdentityProvider identityProvider) { return new IdentityProviderModifiedEvent(identityProvider, getContextAuthentication(), AuditEventType.IdentityProviderModifiedEvent); } diff --git a/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/IdentityZoneModifiedEvent.java b/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/IdentityZoneModifiedEvent.java index 1783a51e3bf..0277c161ef3 100644 --- a/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/IdentityZoneModifiedEvent.java +++ b/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/IdentityZoneModifiedEvent.java @@ -15,7 +15,6 @@ import org.cloudfoundry.identity.uaa.audit.AuditEvent; import org.cloudfoundry.identity.uaa.audit.AuditEventType; import org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent; -import org.cloudfoundry.identity.uaa.util.JsonUtils; import org.cloudfoundry.identity.uaa.zone.IdentityZone; import org.springframework.security.core.Authentication; @@ -25,6 +24,8 @@ public class IdentityZoneModifiedEvent extends AbstractUaaEvent { private AuditEventType eventType; + protected static final String dataFormat = "id=%s; subdomain=%s"; + public IdentityZoneModifiedEvent(IdentityZone identityZone, Authentication authentication, AuditEventType type) { super(identityZone, authentication); eventType = type; @@ -32,8 +33,15 @@ public IdentityZoneModifiedEvent(IdentityZone identityZone, Authentication authe @Override public AuditEvent getAuditEvent() { - return createAuditRecord(getSource().toString(), eventType, getOrigin(getAuthentication()), - JsonUtils.writeValueAsString(source)); + IdentityZone zone = (IdentityZone)source; + return createAuditRecord( + getSource().toString(), + eventType, + getOrigin(getAuthentication()), + String.format(IdentityZoneModifiedEvent.dataFormat, + zone.getId(), + zone.getSubdomain()) + ); } public static IdentityZoneModifiedEvent identityZoneCreated(IdentityZone identityZone) { diff --git a/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEvent.java b/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEvent.java index 296ce9e4752..75727ca6c79 100644 --- a/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEvent.java +++ b/server/src/main/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEvent.java @@ -17,18 +17,16 @@ import org.cloudfoundry.identity.uaa.audit.AuditEventType; import org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent; import org.cloudfoundry.identity.uaa.provider.saml.idp.SamlServiceProvider; -import org.cloudfoundry.identity.uaa.util.JsonUtils; import org.springframework.security.core.Authentication; public class ServiceProviderModifiedEvent extends AbstractUaaEvent { - /** - * Generated serialization id. - */ private static final long serialVersionUID = -204120790766086570L; private AuditEventType eventType; + protected static final String dataFormat = "id=%s; name=%s; entityID=%s"; + public ServiceProviderModifiedEvent(SamlServiceProvider serviceProvider, Authentication authentication, AuditEventType type) { super(serviceProvider, authentication); eventType = type; @@ -36,7 +34,14 @@ public ServiceProviderModifiedEvent(SamlServiceProvider serviceProvider, Authent @Override public AuditEvent getAuditEvent() { - return createAuditRecord(getSource().toString(), eventType, getOrigin(getAuthentication()), JsonUtils.writeValueAsString(source)); + SamlServiceProvider provider = (SamlServiceProvider)source; + return createAuditRecord(getSource().toString(), + eventType, + getOrigin(getAuthentication()), + String.format(dataFormat, + provider.getId(), + provider.getName(), + provider.getEntityId())); } public static ServiceProviderModifiedEvent serviceProviderCreated(SamlServiceProvider serviceProvider) { diff --git a/server/src/test/java/org/cloudfoundry/identity/uaa/audit/event/EntityDeletedEventTest.java b/server/src/test/java/org/cloudfoundry/identity/uaa/audit/event/EntityDeletedEventTest.java new file mode 100644 index 00000000000..65c8d582a27 --- /dev/null +++ b/server/src/test/java/org/cloudfoundry/identity/uaa/audit/event/EntityDeletedEventTest.java @@ -0,0 +1,57 @@ +/* + * **************************************************************************** + * Cloud Foundry + * Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved. + * + * This product is licensed to you under the Apache License, Version 2.0 (the "License"). + * You may not use this product except in compliance with the License. + * + * This product includes a number of subcomponents with + * separate copyright notices and license terms. Your use of these + * subcomponents is subject to the terms and conditions of the + * subcomponent's license, as noted in the LICENSE file. + * **************************************************************************** + */ + +package org.cloudfoundry.identity.uaa.audit.event; + +import org.cloudfoundry.identity.uaa.provider.IdentityProvider; +import org.cloudfoundry.identity.uaa.provider.IdentityProviderValidationRequest; +import org.cloudfoundry.identity.uaa.zone.IdentityZone; +import org.junit.Before; +import org.junit.Test; + +import static org.cloudfoundry.identity.uaa.audit.event.EntityDeletedEvent.dataFormat; +import static org.junit.Assert.assertEquals; + +public class EntityDeletedEventTest { + + + private IdentityProvider provider; + private IdentityZone zone; + + @Before + public void setup() throws Exception { + provider = new IdentityProvider(); + provider.setId("id"); + + zone = IdentityZone.getUaa(); + } + + @Test + public void getAuditEvent_IdentityProvider() throws Exception { + String expected = String.format(dataFormat, IdentityZone.class.getName(), zone.getId()); + evalute(zone, expected); + } + + @Test + public void getAuditEvent_IdentityZone() throws Exception { + String expected = String.format(dataFormat, IdentityProvider.class.getName(), provider.getId()); + evalute(provider, expected); + } + + public void evalute(Object o, String expected) { + EntityDeletedEvent event = new EntityDeletedEvent(o, new IdentityProviderValidationRequest.UsernamePasswordAuthentication("username","password")); + assertEquals(expected, event.getAuditEvent().getData()); + } +} \ No newline at end of file diff --git a/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/IdentityProviderModifiedEventTest.java b/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/IdentityProviderModifiedEventTest.java new file mode 100644 index 00000000000..bc55d0d3c6d --- /dev/null +++ b/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/IdentityProviderModifiedEventTest.java @@ -0,0 +1,87 @@ +/* + * **************************************************************************** + * Cloud Foundry + * Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved. + * + * This product is licensed to you under the Apache License, Version 2.0 (the "License"). + * You may not use this product except in compliance with the License. + * + * This product includes a number of subcomponents with + * separate copyright notices and license terms. Your use of these + * subcomponents is subject to the terms and conditions of the + * subcomponent's license, as noted in the LICENSE file. + * **************************************************************************** + */ + +package org.cloudfoundry.identity.uaa.zone.event; + +import org.cloudfoundry.identity.uaa.constants.OriginKeys; +import org.cloudfoundry.identity.uaa.provider.IdentityProvider; +import org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition; +import org.cloudfoundry.identity.uaa.provider.saml.BootstrapSamlIdentityProviderConfiguratorTests; +import org.cloudfoundry.identity.uaa.zone.IdentityZone; +import org.junit.Before; +import org.junit.Test; +import org.springframework.security.oauth2.common.util.RandomValueStringGenerator; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + + +public class IdentityProviderModifiedEventTest { + + private IdentityProvider provider; + + @Before + public void setup() { + String origin = "idp-mock-saml-"+new RandomValueStringGenerator().generate(); + String metadata = String.format(BootstrapSamlIdentityProviderConfiguratorTests.xmlWithoutID, "http://localhost:9999/metadata/"+origin); + provider = new IdentityProvider<>(); + provider.setId("id"); + provider.setActive(true); + provider.setName(origin); + provider.setIdentityZoneId(IdentityZone.getUaa().getId()); + provider.setType(OriginKeys.SAML); + provider.setIdentityZoneId(IdentityZone.getUaa().getId()); + provider.setOriginKey(origin); + SamlIdentityProviderDefinition samlDefinition = + new SamlIdentityProviderDefinition() + .setMetaDataLocation(metadata) + .setLinkText("Test SAML Provider"); + samlDefinition.setEmailDomain(Arrays.asList("test.com", "test2.com")); + List externalGroupsWhitelist = new ArrayList<>(); + externalGroupsWhitelist.add("value"); + Map attributeMappings = new HashMap<>(); + attributeMappings.put("given_name", "first_name"); + samlDefinition.setExternalGroupsWhitelist(externalGroupsWhitelist); + samlDefinition.setAttributeMappings(attributeMappings); + provider.setConfig(samlDefinition); + } + + @Test + public void identityProviderCreated() throws Exception { + evaluateEventString(IdentityProviderModifiedEvent.identityProviderCreated(provider)); + } + + @Test + public void identityProviderModified() throws Exception { + evaluateEventString(IdentityProviderModifiedEvent.identityProviderModified(provider)); + } + + public void evaluateEventString(IdentityProviderModifiedEvent event) { + String s = event.getAuditEvent().getData(); + assertEquals( + String.format(IdentityProviderModifiedEvent.dataFormat, + provider.getId(), + provider.getType(), + provider.getOriginKey(), + provider.getIdentityZoneId()), + s); + } + +} \ No newline at end of file diff --git a/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/IdentityZoneModifiedEventTest.java b/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/IdentityZoneModifiedEventTest.java new file mode 100644 index 00000000000..4b09b80e4ff --- /dev/null +++ b/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/IdentityZoneModifiedEventTest.java @@ -0,0 +1,68 @@ +/* + * **************************************************************************** + * Cloud Foundry + * Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved. + * + * This product is licensed to you under the Apache License, Version 2.0 (the "License"). + * You may not use this product except in compliance with the License. + * + * This product includes a number of subcomponents with + * separate copyright notices and license terms. Your use of these + * subcomponents is subject to the terms and conditions of the + * subcomponent's license, as noted in the LICENSE file. + * **************************************************************************** + */ + +package org.cloudfoundry.identity.uaa.zone.event; + +import org.cloudfoundry.identity.uaa.zone.IdentityZone; +import org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + + +public class IdentityZoneModifiedEventTest { + + private IdentityZone zone; + + @Before + public void setup() { + zone = new IdentityZone(); + zone.setId("id"); + zone.setSubdomain("subdomain"); + zone.setName("Test Zone"); + zone.setDescription("Test Zone Description"); + zone.setConfig(new IdentityZoneConfiguration()); + zone.getConfig().getSamlConfig().setPrivateKey("key"); + zone.getConfig().getSamlConfig().setPrivateKeyPassword("password"); + zone.getConfig().getSamlConfig().setCertificate("certificate"); + Map keys = new HashMap<>(); + keys.put("kid", "key"); + zone.getConfig().getTokenPolicy().setKeys(keys); + + } + + @Test + public void identityZoneCreated() throws Exception { + evaluteZoneAuditData(IdentityZoneModifiedEvent.identityZoneCreated(zone)); + } + + @Test + public void identityZoneModified() throws Exception { + evaluteZoneAuditData(IdentityZoneModifiedEvent.identityZoneModified(zone)); + } + + public void evaluteZoneAuditData(IdentityZoneModifiedEvent event) { + String s = event.getAuditEvent().getData(); + assertEquals(String.format(IdentityZoneModifiedEvent.dataFormat, + zone.getId(), + zone.getSubdomain()), + s); + } + +} \ No newline at end of file diff --git a/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEventTest.java b/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEventTest.java new file mode 100644 index 00000000000..5455fa5474f --- /dev/null +++ b/server/src/test/java/org/cloudfoundry/identity/uaa/zone/event/ServiceProviderModifiedEventTest.java @@ -0,0 +1,63 @@ +/* + * **************************************************************************** + * Cloud Foundry + * Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved. + * + * This product is licensed to you under the Apache License, Version 2.0 (the "License"). + * You may not use this product except in compliance with the License. + * + * This product includes a number of subcomponents with + * separate copyright notices and license terms. Your use of these + * subcomponents is subject to the terms and conditions of the + * subcomponent's license, as noted in the LICENSE file. + * **************************************************************************** + */ + +package org.cloudfoundry.identity.uaa.zone.event; + +import org.cloudfoundry.identity.uaa.provider.saml.idp.SamlServiceProvider; +import org.cloudfoundry.identity.uaa.util.JsonUtils; +import org.junit.Before; +import org.junit.Test; +import org.springframework.security.oauth2.common.util.RandomValueStringGenerator; + +import static org.junit.Assert.assertEquals; + + +public class ServiceProviderModifiedEventTest { + + private SamlServiceProvider provider; + + @Before + public void setup() { + String name = new RandomValueStringGenerator().generate(); + String requestBody = "{\n" + + " \"name\" : \"" + name + "\",\n" + + " \"entityId\" : \""+ name +".cloudfoundry-saml-login\",\n" + + " \"active\" : true,\n" + + " \"config\" : \"{\\\"metaDataLocation\\\" : \\\"zALgjEFJ7jJSwn2AOBH5H8CX93U=Rp5XH8eT0ek/vlFGzHgIFOeESchOwSYZ9oh4JA9WqQ0jJtvNQ9IttY2QY9XK3n6TbbtPcEKVgljyTfwD5ymp+oMKfIYQC9JsN8mPADN5rjLFgC+xGceWLbcjoNsCJ7x2ZjyWRblSxoOU5qnzxEA3k3Bu+OkV+ZXcSbmgMWoQACg=MIIDSTCCArKgAwIBAgIBADANBgkqhkiG9w0BAQQFADB8MQswCQYDVQQGEwJhdzEOMAwGA1UECBMF\\\\nYXJ1YmExDjAMBgNVBAoTBWFydWJhMQ4wDAYDVQQHEwVhcnViYTEOMAwGA1UECxMFYXJ1YmExDjAM\\\\nBgNVBAMTBWFydWJhMR0wGwYJKoZIhvcNAQkBFg5hcnViYUBhcnViYS5hcjAeFw0xNTExMjAyMjI2\\\\nMjdaFw0xNjExMTkyMjI2MjdaMHwxCzAJBgNVBAYTAmF3MQ4wDAYDVQQIEwVhcnViYTEOMAwGA1UE\\\\nChMFYXJ1YmExDjAMBgNVBAcTBWFydWJhMQ4wDAYDVQQLEwVhcnViYTEOMAwGA1UEAxMFYXJ1YmEx\\\\nHTAbBgkqhkiG9w0BCQEWDmFydWJhQGFydWJhLmFyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\\\\ngQDHtC5gUXxBKpEqZTLkNvFwNGnNIkggNOwOQVNbpO0WVHIivig5L39WqS9u0hnA+O7MCA/KlrAR\\\\n4bXaeVVhwfUPYBKIpaaTWFQR5cTR1UFZJL/OF9vAfpOwznoD66DDCnQVpbCjtDYWX+x6imxn8HCY\\\\nxhMol6ZnTbSsFW6VZjFMjQIDAQABo4HaMIH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1YmEx\\\\nHTAbBgkqhkiG9w0BCQEWDmFydWJhQGFydWJhLmFyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\\\\ngQDHtC5gUXxBKpEqZTLkNvFwNGnNIkggNOwOQVNbpO0WVHIivig5L39WqS9u0hnA+O7MCA/KlrAR\\\\n4bXaeVVhwfUPYBKIpaaTWFQR5cTR1UFZJL/OF9vAfpOwznoD66DDCnQVpbCjtDYWX+x6imxn8HCY\\\\nxhMol6ZnTbSsFW6VZjFMjQIDAQABo4HaMIHXMB0GA1UdDgQWBBTx0lDzjH/iOBnOSQaSEWQLx1sy\\\\nGDCBpwYDVR0jBIGfMIGcgBTx0lDzjH/iOBnOSQaSEWQLx1syGKGBgKR+MHwxCzAJBgNVBAYTAmF3\\\\nMQ4wDAYDVQQIEwVhcnViYTEOMAwGA1UEChMFYXJ1YmExDjAMBgNVBAcTBWFydWJhMQ4wDAYDVQQL\\\\nEwVhcnViYTEOMAwGA1UEAxMFYXJ1YmExHTAbBgkqhkiG9w0BCQEWDmFydWJhQGFydWJhLmFyggEA\\\\nMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAYvBJ0HOZbbHClXmGUjGs+GS+xC1FO/am\\\\n2suCSYqNB9dyMXfOWiJ1+TLJk+o/YZt8vuxCKdcZYgl4l/L6PxJ982SRhc83ZW2dkAZI4M0/Ud3o\\\\nePe84k8jm3A7EvH5wi5hvCkKRpuRBwn3Ei+jCRouxTbzKPsuCVB+1sNyxMTXzf0=urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddressurn:oasis:names:tc:SAML:2.0:nameid-format:transienturn:oasis:names:tc:SAML:2.0:nameid-format:persistenturn:oasis:names:tc:SAML:1.1:nameid-format:unspecifiedurn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName\\\",\\\"metadataTrustCheck\\\" : true }\"" + + "}"; + provider = JsonUtils.readValue(requestBody, SamlServiceProvider.class); + + } + @Test + public void serviceProviderCreated() throws Exception { + evaludateAuditEventData(ServiceProviderModifiedEvent.serviceProviderCreated(provider)); + } + + @Test + public void serviceProviderModified() throws Exception { + evaludateAuditEventData(ServiceProviderModifiedEvent.serviceProviderModified(provider)); + } + + public void evaludateAuditEventData(ServiceProviderModifiedEvent event) { + assertEquals( + String.format(ServiceProviderModifiedEvent.dataFormat, + provider.getId(), + provider.getName(), + provider.getEntityId()), + event.getAuditEvent().getData() + ); + } + +} \ No newline at end of file diff --git a/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/zones/IdentityZoneEndpointsMockMvcTests.java b/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/zones/IdentityZoneEndpointsMockMvcTests.java index 8e531c7c038..f7d52cb827b 100644 --- a/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/zones/IdentityZoneEndpointsMockMvcTests.java +++ b/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/zones/IdentityZoneEndpointsMockMvcTests.java @@ -63,6 +63,7 @@ import static org.cloudfoundry.identity.uaa.constants.OriginKeys.UAA; import static org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.CookieCsrfPostProcessor.cookieCsrf; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.collection.IsEmptyCollection.empty; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; @@ -912,8 +913,8 @@ public void testDeleteZonePublishesEvent() throws Exception { IdentityZone deletedZone = (IdentityZone) deletedEvent.getDeleted(); assertThat(deletedZone.getId(), is(id)); assertThat(deletedEvent.getIdentityZone().getId(), is(id)); - IdentityZone auditedIdentityZone = JsonUtils.readValue(deletedEvent.getAuditEvent().getData(), IdentityZone.class); - assertThat(auditedIdentityZone.getId(), is(id)); + String auditedIdentityZone = deletedEvent.getAuditEvent().getData(); + assertThat(auditedIdentityZone, containsString(id)); } @Test