Skip to content

Commit

Permalink
Fix tests for id card levels
Browse files Browse the repository at this point in the history
  • Loading branch information
tgk committed Oct 31, 2011
1 parent a74dc15 commit c40266c
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 24 deletions.
Expand Up @@ -211,7 +211,7 @@ public void doFilter(ServletRequest request, final ServletResponse response, fin
}
else
{
Reply reply = factory.createNewErrorReply(DGWSConstants.VERSION_1_0_1, "0", "0", FaultCodeValues.SECURITY_LEVEL_FAILED, "The invalid security level.");
Reply reply = factory.createNewErrorReply(DGWSConstants.VERSION_1_0_1, "0", "0", FaultCodeValues.SECURITY_LEVEL_FAILED, "Invalid security level.");
writeFaultToResponse(httpResponse, reply);
}
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
package dk.nsi.stamdata.performance;

import dk.nsi.stamdata.testing.MockSecureTokenService;
import dk.sosi.seal.model.AuthenticationLevel;
import dk.sosi.seal.model.Request;
import dk.sosi.seal.model.SystemIDCard;
import dk.sosi.seal.xml.XmlUtil;
Expand Down Expand Up @@ -81,7 +82,7 @@ public SampleResult runTest(JavaSamplerContext context)

private String createIdCard() throws Exception
{
SystemIDCard idCard = MockSecureTokenService.createSignedSystemIDCard(SOSITestConstants.TEST_CVR);
SystemIDCard idCard = MockSecureTokenService.createSignedSystemIDCard(SOSITestConstants.TEST_CVR, AuthenticationLevel.VOCES_TRUSTED_SYSTEM);
Request createNewRequest = MockSecureTokenService.createFactory().createNewRequest(false, "flowId");
createNewRequest.setIDCard(idCard);

Expand Down
Expand Up @@ -138,15 +138,16 @@ public static SOSIFactory createFactory()
private MockSecureTokenService()
{}


public static SystemIDCard createSignedSystemIDCard(String cvr)
public static SystemIDCard createSignedSystemIDCard(String cvr, AuthenticationLevel auth)
{
String username = null; // Only used for level 2
String password = null; // Only used for level 2

CareProvider careProvider = new CareProvider(SubjectIdentifierTypeValues.CVR_NUMBER, cvr, "dk");
SystemIDCard idCard = createFactory().createNewSystemIDCard("ACME Pro", careProvider, AuthenticationLevel.VOCES_TRUSTED_SYSTEM, username, password, certificate, "123");

return idCard;
String username = "Brian"; // Only used for level 2
String password = "Graversen"; // Only used for level 2
CareProvider careProvider = new CareProvider(SubjectIdentifierTypeValues.CVR_NUMBER, cvr, "dk");
SystemIDCard idCard = createFactory().createNewSystemIDCard("ACME Pro", careProvider, auth, username, password, certificate, "123");
return idCard;
}


}
1 change: 0 additions & 1 deletion nsp/batch-copy-ws/src/main/resources/config.properties
@@ -1,2 +1 @@
dk.nsi.dgws.sosi.nistLevels=3

Expand Up @@ -135,7 +135,7 @@ private static Header getMedComHeader(String messageId)
private static Request getRequest(AuthenticationLevel auth, SOSIFactory factory, String cvr, String careProviderName, String itSystemName) throws CertificateException
{
Request request = factory.createNewRequest(false, null);
SystemIDCard idCard = MockSecureTokenService.createSignedSystemIDCard(cvr);
SystemIDCard idCard = MockSecureTokenService.createSignedSystemIDCard(cvr, auth);
request.setIDCard(idCard);
return request;
}
Expand Down
Expand Up @@ -110,6 +110,8 @@ public void levelFourRequestRaisesAnException() throws Exception {
attemptCallWithLevel(4);
}

// Helper methods

private void attemptCallWithLevel(int level) throws ReplicationFault, Exception
{
createCprPersonRegisterReplicationRequest();
Expand All @@ -118,8 +120,6 @@ private void attemptCallWithLevel(int level) throws ReplicationFault, Exception
assertResponseContainsAtom();
assertResponseContainsExactNumberOfRecords("person", 0);
}

// Helper methods

private void createCprPersonRegisterReplicationRequest() {
request = new ObjectFactory().createReplicationRequestType();
Expand Down
Expand Up @@ -50,6 +50,7 @@
import dk.nsi.stamdata.jaxws.generated.PersonPublicHealthInsuranceType;
import dk.nsi.stamdata.jaxws.generated.PersonWithHealthCareInformationStructureType;
import dk.nsi.stamdata.testing.MockSecureTokenService;
import dk.sosi.seal.model.AuthenticationLevel;
import dk.sosi.seal.model.SystemIDCard;


Expand Down Expand Up @@ -79,7 +80,7 @@ private void doMapping() throws DatatypeConfigurationException
{
MunicipalityMapper municipalityMapper = new MunicipalityMapper();
Set<String> whitelist = Sets.newHashSet();
SystemIDCard idCard = MockSecureTokenService.createSignedSystemIDCard(NOT_WHITELISTED_CVR);
SystemIDCard idCard = MockSecureTokenService.createSignedSystemIDCard(NOT_WHITELISTED_CVR, AuthenticationLevel.VOCES_TRUSTED_SYSTEM);

output = new PersonMapper(whitelist, idCard, municipalityMapper).map(person, relation, yder);
}
Expand Down
Expand Up @@ -49,6 +49,7 @@
import dk.nsi.stamdata.jaxws.generated.PersonGenderCodeType;
import dk.nsi.stamdata.jaxws.generated.PersonInformationStructureType;
import dk.nsi.stamdata.testing.MockSecureTokenService;
import dk.sosi.seal.model.AuthenticationLevel;
import dk.sosi.seal.model.SystemIDCard;


Expand Down Expand Up @@ -324,7 +325,7 @@ public void omitsCountyCode()
private void doMap() throws Exception
{
Set<String> whiteList = Sets.newHashSet();
SystemIDCard idCard = MockSecureTokenService.createSignedSystemIDCard("12345678");
SystemIDCard idCard = MockSecureTokenService.createSignedSystemIDCard("12345678", AuthenticationLevel.VOCES_TRUSTED_SYSTEM);
MunicipalityMapper municipalityMapper = new MunicipalityMapper();

PersonMapper personMapper = new PersonMapper(whiteList, idCard, municipalityMapper);
Expand Down
Expand Up @@ -50,6 +50,7 @@
import dk.nsi.stamdata.jaxws.generated.PersonInformationStructureType;
import dk.nsi.stamdata.jaxws.generated.PersonWithHealthCareInformationStructureType;
import dk.nsi.stamdata.testing.MockSecureTokenService;
import dk.sosi.seal.model.AuthenticationLevel;
import dk.sosi.seal.model.SystemIDCard;

@RunWith(MockitoJUnitRunner.class)
Expand Down Expand Up @@ -83,8 +84,8 @@ public void setUp()
{
whitelist = Sets.newHashSet(WHITELISTED_CVR);

nonWhitelistedIDCard = MockSecureTokenService.createSignedSystemIDCard(NON_WHITELISTED_CVR);
whitelistedIDCard = MockSecureTokenService.createSignedSystemIDCard(WHITELISTED_CVR);
nonWhitelistedIDCard = MockSecureTokenService.createSignedSystemIDCard(NON_WHITELISTED_CVR, AuthenticationLevel.VOCES_TRUSTED_SYSTEM);
whitelistedIDCard = MockSecureTokenService.createSignedSystemIDCard(WHITELISTED_CVR, AuthenticationLevel.VOCES_TRUSTED_SYSTEM);

municipalityMapper = new MunicipalityMapper();
person = Factories.createPerson();
Expand Down
Expand Up @@ -34,7 +34,6 @@

import javax.xml.namespace.QName;
import javax.xml.ws.Holder;
import javax.xml.ws.soap.SOAPFaultException;

import org.hisrc.hifaces20.testing.webappenvironment.testing.junit4.AbstractWebAppEnvironmentJUnit4Test;
import org.junit.Before;
Expand Down Expand Up @@ -86,12 +85,12 @@ public void setUp() throws Exception {
client = serviceCatalog.getStamdataPersonLookup();
}

@Test(expected = SOAPFaultException.class)
@Test(expected = DGWSFault.class)
public void requestWithLevelOneIdCardRaisesAnException() throws Exception {
sendRequestWithGivenSecurityLevel(1);
}

@Test(expected = SOAPFaultException.class)
@Test(expected = DGWSFault.class)
public void requestWithLevelTwoIdCardRaisesAnException() throws Exception {
sendRequestWithGivenSecurityLevel(2);
}
Expand All @@ -101,7 +100,7 @@ public void requestWithLevelthreeIdCardDoesNotRaisesAnException() throws Excepti
sendRequestWithGivenSecurityLevel(3);
}

@Test(expected = SOAPFaultException.class)
@Test(expected = DGWSFault.class)
public void requestWithLevelFourIdCardRaisesAnException() throws Exception {
sendRequestWithGivenSecurityLevel(4);
}
Expand Down
Expand Up @@ -136,7 +136,7 @@ private static Header getMedComHeader(String messageId)
private static Request getRequest(AuthenticationLevel auth, SOSIFactory factory, String cvr, String careProviderName, String itSystemName) throws CertificateException
{
Request request = factory.createNewRequest(false, null);
SystemIDCard idCard = MockSecureTokenService.createSignedSystemIDCard(cvr);
SystemIDCard idCard = MockSecureTokenService.createSignedSystemIDCard(cvr, auth);
request.setIDCard(idCard);
return request;
}
Expand Down

0 comments on commit c40266c

Please sign in to comment.