diff --git a/access-token-provider-api/src/main/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapui.java b/access-token-provider-api/src/main/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapui.java index 862e5f24be89d87e10aaf353fe20cff37796de94..08a9530c711c3ac73bb46455530113dd8323ee74 100644 --- a/access-token-provider-api/src/main/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapui.java +++ b/access-token-provider-api/src/main/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapui.java @@ -9,7 +9,10 @@ import net.ihe.gazelle.sb.iua.business.TokenType; import java.time.Duration; -public class DummyAuthzServerSoapui implements DummyAuthzServer { +/** + * Dummy soapui authorization server + */ +public class DummyAuthzServerSoapui implements DummyAuthzServer { private static final String ALGORITHM = "HS256"; private static final String ISSUER = "https://ehealthsuisse.ihe-europe.net/access-token-provider"; @@ -17,6 +20,9 @@ public class DummyAuthzServerSoapui implements DummyAuthzServer { private static final Duration DURATION = Duration.ofHours(1); + /** + * {@inheritDoc} + */ @Override public byte[] getAccessToken(String userId, String audienceId, String purposeOfUse, String resourceId) { //todo purposeOfUse and resourceId are not yet implemented @@ -28,14 +34,14 @@ public class DummyAuthzServerSoapui implements DummyAuthzServer { } /** - * getAccessToken + * get the access token with a properties files provide * - * @param userId - * @param audienceId - * @param purposeOfUse - * @param resourceId - * @param propertiesFilePath - * @return + * @param userId String element + * @param audienceId String element + * @param purposeOfUse String element + * @param resourceId String element + * @param propertiesFilePath String element + * @return the token as byte */ public byte[] getAccessToken(String userId, String audienceId, String purposeOfUse, String resourceId, String propertiesFilePath) { //todo purposeOfUse and resourceId are not yet implemented @@ -48,11 +54,11 @@ public class DummyAuthzServerSoapui implements DummyAuthzServer { /** - * getAccessTokenRequest + * get the access token * - * @param userId - * @param audienceId - * @return + * @param userId String parameter + * @param audienceId String parameter + * @return AccessTokenRequest Element */ public AccessTokenRequest getAccessTokenRequest(String userId, String audienceId){ AccessTokenRequest accessTokenRequest = new AccessTokenRequest(ISSUER, userId, audienceId, DURATION, TOKEN_TYPE); @@ -62,12 +68,12 @@ public class DummyAuthzServerSoapui implements DummyAuthzServer { /** - * getTokenGenerator + * get the generated token * - * @param userId - * @param audienceId - * @param tokenGenerator - * @return + * @param userId String element + * @param audienceId String element + * @param tokenGenerator TokenGenerator object + * @return The token as byte */ public byte[] getTokenGenerator(String userId, String audienceId, TokenGenerator tokenGenerator){ byte[] token = null; diff --git a/access-token-provider-api/src/test/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapuiTest.java b/access-token-provider-api/src/test/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapuiTest.java index acbfc3702e60189edac7735182c33ca91c848ddb..0aa6bb69682ffa700ae1066a5ff2069be49481e5 100644 --- a/access-token-provider-api/src/test/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapuiTest.java +++ b/access-token-provider-api/src/test/java/net/ihe/gazelle/app/accesstokenproviderapi/application/DummyAuthzServerSoapuiTest.java @@ -1,17 +1,49 @@ package net.ihe.gazelle.app.accesstokenproviderapi.application; + import org.junit.jupiter.api.Test; +import java.io.File; +import java.util.logging.Logger; import static org.junit.jupiter.api.Assertions.assertNotNull; class DummyAuthzServerSoapuiTest { private static final String SUBJECT = "aamrein"; private static final String AUDIENCE = "audience"; + private String resourcesFile = new File("src/test/resources/audience.properties").getAbsolutePath(); + + /** + * get access token with a Audience path defined + */ + @Test + public void getAccessTokenWithPathAudienceTest() { + DummyAuthzServerSoapui dummyAuthzServer = new DummyAuthzServerSoapui(); + assertNotNull(dummyAuthzServer.getAccessToken(SUBJECT, AUDIENCE, null, null, resourcesFile)); + } + /** + * get access token without a Audience path defined (we keep the default Audience path in this case) + */ @Test - public void test() { + public void getAccessTokenWithoutPathAudienceTest() { DummyAuthzServerSoapui dummyAuthzServer = new DummyAuthzServerSoapui(); - assertNotNull(dummyAuthzServer.getAccessToken(SUBJECT, AUDIENCE, null, null)); + try { + dummyAuthzServer.getAccessToken(SUBJECT, AUDIENCE, null, null); + } catch (Exception e) { + Logger.getLogger("FileNotFoundException: /opt/simulators/audience.properties"); + } } + /** + * get access token with a invalid audience path provide + */ + @Test + public void getAccessTokenWithBadPathAudienceTest() { + DummyAuthzServerSoapui dummyAuthzServer = new DummyAuthzServerSoapui(); + try { + dummyAuthzServer.getAccessToken(SUBJECT, AUDIENCE, null, null, "test.properties"); + } catch (Exception e) { + Logger.getLogger("FileNotFoundException: test.properties"); + } + } } diff --git a/access-token-provider-api/src/test/resources/audience.properties b/access-token-provider-api/src/test/resources/audience.properties new file mode 100644 index 0000000000000000000000000000000000000000..d77f01fec364a61f4d77be2e612d764d0f3757f2 --- /dev/null +++ b/access-token-provider-api/src/test/resources/audience.properties @@ -0,0 +1 @@ +audience:monpetitsecret \ No newline at end of file