use of com.auth0.json.mgmt.Connection in project auth0-java by auth0.
the class ConnectionsEntityTest method shouldUpdateConnection.
@Test
public void shouldUpdateConnection() throws Exception {
Request<Connection> request = api.connections().update("1", new Connection("my-connection", "auth0"));
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_CONNECTION, 200);
Connection response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/connections/1"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
Map<String, Object> body = bodyFromRequest(recordedRequest);
assertThat(body.size(), is(2));
assertThat(body, hasEntry("name", "my-connection"));
assertThat(body, hasEntry("strategy", "auth0"));
assertThat(response, is(notNullValue()));
}
use of com.auth0.json.mgmt.Connection in project auth0-java by auth0.
the class ConnectionsEntityTest method shouldGetConnectionWithFields.
@Test
public void shouldGetConnectionWithFields() throws Exception {
ConnectionFilter filter = new ConnectionFilter().withFields("some,random,fields", true);
Request<Connection> request = api.connections().get("1", filter);
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_CONNECTION, 200);
Connection response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/connections/1"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
assertThat(recordedRequest, hasQueryParameter("fields", "some,random,fields"));
assertThat(recordedRequest, hasQueryParameter("include_fields", "true"));
assertThat(response, is(notNullValue()));
}
use of com.auth0.json.mgmt.Connection in project auth0-java by auth0.
the class UsersEntityTest method shouldUpdateUser.
@Test
public void shouldUpdateUser() throws Exception {
Request<User> request = api.users().update("1", new User("auth0"));
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_USER, 200);
User response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/users/1"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
Map<String, Object> body = bodyFromRequest(recordedRequest);
assertThat(body.size(), is(1));
assertThat(body, hasEntry("connection", "auth0"));
assertThat(response, is(notNullValue()));
}
use of com.auth0.json.mgmt.Connection in project auth0-java by auth0.
the class UsersEntityTest method shouldCreateUser.
@Test
public void shouldCreateUser() throws Exception {
Request<User> request = api.users().create(new User("auth0"));
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_USER, 200);
User response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/users"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
Map<String, Object> body = bodyFromRequest(recordedRequest);
assertThat(body.size(), is(1));
assertThat(body, hasEntry("connection", "auth0"));
assertThat(response, is(notNullValue()));
}
use of com.auth0.json.mgmt.Connection in project pic-sure-auth-microapp by hms-dbmi.
the class Auth0MatchingServiceTest method testMatchTokenToUser.
@Test
public void testMatchTokenToUser() {
String ldapToken = "ldap-connector-access-token";
String githubToken = "github-access-token";
String nihToken = "nih-gov-prod-access-token";
try {
JsonNode userInfo = mockAuthAPIUserInfo(ldapToken);
// Test when everything works fine
User result = cut.matchTokenToUser(userInfo);
assertNotNull(result);
assertNotNull(result.getAuth0metadata());
assertNotNull(result.getSubject());
assertEquals("ad|ldap-connector|blablablablablablablablablablablabla", result.getSubject());
assertTrue(result.isMatched());
assertNotNull(persistedUser);
assertNotNull(persistedUser.getAuth0metadata());
assertEquals(persistedUser.getAuth0metadata(), result.getAuth0metadata());
assertNotNull(persistedUser.getSubject());
assertEquals("ad|ldap-connector|blablablablablablablablablablablabla", persistedUser.getSubject());
assertTrue(persistedUser.isMatched());
// Reset
persistedUser = null;
// Test when multiple mappings in database
userInfo = mockAuthAPIUserInfo(githubToken);
result = cut.matchTokenToUser(userInfo);
assertNotNull(result);
assertNotNull(result.getAuth0metadata());
assertNotNull(result.getSubject());
assertEquals("github|0000000", result.getSubject());
assertTrue(result.isMatched());
assertNotNull(persistedUser);
assertNotNull(persistedUser.getAuth0metadata());
assertEquals(persistedUser.getAuth0metadata(), result.getAuth0metadata());
assertNotNull(persistedUser.getSubject());
assertEquals("github|0000000", persistedUser.getSubject());
assertTrue(persistedUser.isMatched());
persistedUser = null;
// Test when path not found in user generalmetadata
userInfo = mockAuthAPIUserInfo(nihToken);
result = cut.matchTokenToUser(userInfo);
assertNotNull(result);
assertNotNull(result.getAuth0metadata());
assertNotNull(result.getSubject());
assertEquals("samlp|NOBODY", result.getSubject());
assertTrue(result.isMatched());
assertNotNull(persistedUser);
assertNotNull(persistedUser.getAuth0metadata());
assertEquals(persistedUser.getAuth0metadata(), result.getAuth0metadata());
assertNotNull(persistedUser.getSubject());
assertEquals("samlp|NOBODY", persistedUser.getSubject());
assertTrue(persistedUser.isMatched());
persistedUser = null;
// Test when no user matches
userInfo = mockAuthAPIUserInfo("no-user-token");
result = cut.matchTokenToUser(userInfo);
assertNull(result);
// Test when path not found in auth0metadata -- This is a problem with the mapping data in the database
userInfo = mockAuthAPIUserInfo("invalid-path-token");
result = cut.matchTokenToUser(userInfo);
assertNull(result);
// Test when no mappings in database -- We have no mappings set up for this yet
userInfo = mockAuthAPIUserInfo("no-mapping-connection-token");
result = cut.matchTokenToUser(userInfo);
assertNull(result);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations