Skip to content

Commit

Permalink
Add tests for validation of AuthenticationProviderConfiguration. IQSS…
Browse files Browse the repository at this point in the history
  • Loading branch information
poikilotherm committed Mar 16, 2020
1 parent cc90c01 commit 8ba09ca
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.harvard.iq.dataverse.authorization.providers;

import edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationProviderConfigurationException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -38,4 +39,27 @@ void parseValid(String filename) throws Exception {

assertNotNull(config);
}

@Test
void testValidatorLoading() throws Exception {
assertDoesNotThrow(() -> AuthenticationProviderConfigurationParser.getValidator());
}

@ParameterizedTest
@ValueSource(strings = {"minimal-valid.json", "title-i18n-valid.json", "orcid-valid.json", "shib-valid.json"})
void validateValid(String filename) throws Exception {
Path file = Paths.get(ClassLoader.getSystemResource("auth-providers/"+filename).toURI());
String content = new String(Files.readAllBytes(file), StandardCharsets.UTF_8);

assertTrue(AuthenticationProviderConfigurationParser.validate(content));
}

@ParameterizedTest
@ValueSource(strings = {"minimal-invalid.json"})
void validateInvalid(String filename) throws Exception {
Path file = Paths.get(ClassLoader.getSystemResource("auth-providers/"+filename).toURI());
String content = new String(Files.readAllBytes(file), StandardCharsets.UTF_8);

assertThrows(AuthenticationProviderConfigurationException.class, () -> AuthenticationProviderConfigurationParser.validate(content));
}
}
6 changes: 6 additions & 0 deletions src/test/resources/auth-providers/minimal-invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "test",
"type": "notexisting",
"enabled": "true",
"title": "Test"
}
12 changes: 12 additions & 0 deletions src/test/resources/auth-providers/orcid-valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "test",
"type": "orcid",
"enabled": true,
"title": {
"en": "Test"
},
"options": {
"client_id": "test",
"client_secret": "test"
}
}
11 changes: 11 additions & 0 deletions src/test/resources/auth-providers/shib-valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "test",
"type": "shib",
"enabled": true,
"title": {
"en": "Test"
},
"options": {
"passive_login": true
}
}

0 comments on commit 8ba09ca

Please sign in to comment.