forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(auth): add integration test for OIDC provisioning via MPCONFIG I…
…QSS#9268 Using Testcontainers to start a Keycloak instance with our default development realm, the provider is created using MPCONFIG settings.
- Loading branch information
1 parent
fb11096
commit 1fb0f58
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...iq/dataverse/authorization/providers/oauth2/oidc/OIDCAuthenticationProviderFactoryIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package edu.harvard.iq.dataverse.authorization.providers.oauth2.oidc; | ||
|
||
import dasniko.testcontainers.keycloak.KeycloakContainer; | ||
import edu.harvard.iq.dataverse.settings.JvmSettings; | ||
import edu.harvard.iq.dataverse.util.testing.JvmSetting; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@Tag("testcontainers") | ||
@Testcontainers | ||
class OIDCAuthenticationProviderFactoryIT { | ||
|
||
static final String clientId = "oidc-client"; | ||
static final String clientSecret = "ss6gE8mODCDfqesQaSG3gwUwZqZt547E"; | ||
static final String realm = "oidc-realm"; | ||
|
||
@Container | ||
static KeycloakContainer keycloakContainer = new KeycloakContainer().withRealmImportFile("keycloak/oidc-realm.json"); | ||
|
||
// simple method to retrieve the issuer URL, referenced to by @JvmSetting annotations | ||
private static String getAuthUrl() { | ||
return keycloakContainer.getAuthServerUrl() + "realms/" + realm; | ||
} | ||
|
||
@Test | ||
@JvmSetting(key = JvmSettings.OIDC_CLIENT_ID, value = clientId) | ||
@JvmSetting(key = JvmSettings.OIDC_CLIENT_SECRET, value = clientSecret) | ||
@JvmSetting(key = JvmSettings.OIDC_AUTH_SERVER_URL, method = "getAuthUrl") | ||
void testCreateProvider() throws Exception { | ||
OIDCAuthProvider oidcAuthProvider = (OIDCAuthProvider) OIDCAuthenticationProviderFactory.buildFromSettings(); | ||
assertTrue(oidcAuthProvider.getMetadata().getTokenEndpointURI().toString().startsWith(keycloakContainer.getAuthServerUrl())); | ||
} | ||
} |