mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
SPRINT-18: fixed unit test on auth0 reuse
This commit is contained in:
@ -167,6 +167,13 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>4.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -193,7 +193,7 @@ public class Auth0AuthenticationModule implements QAuthenticationModuleInterface
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
private static String getIdTokenFromBase64BasicAuthCredentials(AuthAPI auth, String base64Credentials) throws Auth0Exception
|
private String getIdTokenFromBase64BasicAuthCredentials(AuthAPI auth, String base64Credentials) throws Auth0Exception
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// look for a fresh idToken in the state provider for this set of credentials //
|
// look for a fresh idToken in the state provider for this set of credentials //
|
||||||
@ -211,9 +211,25 @@ public class Auth0AuthenticationModule implements QAuthenticationModuleInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// not found in cache, make request to auth0 and cache the returned idToken //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
byte[] credDecoded = Base64.getDecoder().decode(base64Credentials);
|
byte[] credDecoded = Base64.getDecoder().decode(base64Credentials);
|
||||||
String credentials = new String(credDecoded, StandardCharsets.UTF_8);
|
String credentials = new String(credDecoded, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
String idToken = getIdTokenFromAuth0(auth, credentials);
|
||||||
|
stateProvider.put(idTokenStateKey, idToken);
|
||||||
|
stateProvider.put(timestampStateKey, Instant.now());
|
||||||
|
return (idToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
protected String getIdTokenFromAuth0(AuthAPI auth, String credentials) throws Auth0Exception
|
||||||
|
{
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
// call auth0 with a login request //
|
// call auth0 with a login request //
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
@ -221,12 +237,7 @@ public class Auth0AuthenticationModule implements QAuthenticationModuleInterface
|
|||||||
.setScope("openid email nickname")
|
.setScope("openid email nickname")
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
String idToken = result.getIdToken();
|
return (result.getIdToken());
|
||||||
|
|
||||||
stateProvider.put(idTokenStateKey, idToken);
|
|
||||||
stateProvider.put(timestampStateKey, Instant.now());
|
|
||||||
|
|
||||||
return idToken;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import java.time.temporal.ChronoUnit;
|
|||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import com.auth0.exception.Auth0Exception;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QAuthenticationException;
|
import com.kingsrook.qqq.backend.core.exceptions.QAuthenticationException;
|
||||||
import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter;
|
import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||||
@ -47,6 +48,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -247,13 +252,16 @@ public class Auth0AuthenticationModuleTest
|
|||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@Test
|
@Test
|
||||||
void testBasicAuthSuccess() throws QAuthenticationException
|
void testBasicAuthSuccess() throws QAuthenticationException, Auth0Exception
|
||||||
{
|
{
|
||||||
Map<String, String> context = new HashMap<>();
|
Map<String, String> context = new HashMap<>();
|
||||||
context.put(BASIC_AUTH_KEY, encodeBasicAuth("darin.kelkhoff@gmail.com", "6-EQ!XzBJ!F*LRVDK6VZY__92!"));
|
context.put(BASIC_AUTH_KEY, encodeBasicAuth("darin.kelkhoff@gmail.com", "6-EQ!XzBJ!F*LRVDK6VZY__92!"));
|
||||||
|
|
||||||
Auth0AuthenticationModule auth0AuthenticationModule = new Auth0AuthenticationModule();
|
Auth0AuthenticationModule auth0Spy = spy(Auth0AuthenticationModule.class);
|
||||||
auth0AuthenticationModule.createSession(getQInstance(), context);
|
auth0Spy.createSession(getQInstance(), context);
|
||||||
|
auth0Spy.createSession(getQInstance(), context);
|
||||||
|
auth0Spy.createSession(getQInstance(), context);
|
||||||
|
verify(auth0Spy, times(1)).getIdTokenFromAuth0(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
8
qqq-dev-tools/bin/resolve-pom-conflicts.sh
Executable file
8
qqq-dev-tools/bin/resolve-pom-conflicts.sh
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
## resolve-pom-conflicts.sh
|
||||||
|
## Tries to automatically resove pom conflicts by putting SNAPSHOT back
|
||||||
|
############################################################################
|
||||||
|
gsed "/Updated upstream/,/=======/d" pom.xml | gsed "/Stashed/d" > /tmp/temp-pom.xml
|
||||||
|
mv /tmp/temp-pom.xml pom.xml
|
Reference in New Issue
Block a user