Search in sources :

Example 21 with Connection

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()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Connection(com.auth0.json.mgmt.Connection) Test(org.junit.Test)

Example 22 with Connection

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()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ConnectionFilter(com.auth0.client.mgmt.filter.ConnectionFilter) Connection(com.auth0.json.mgmt.Connection) Test(org.junit.Test)

Example 23 with Connection

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()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) User(com.auth0.json.mgmt.users.User) Test(org.junit.Test)

Example 24 with Connection

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()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) User(com.auth0.json.mgmt.users.User) Test(org.junit.Test)

Example 25 with Connection

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();
    }
}
Also used : User(edu.harvard.hms.dbmi.avillach.auth.data.entity.User) JsonNode(com.fasterxml.jackson.databind.JsonNode) Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)13 Connection (com.auth0.json.mgmt.Connection)10 List (java.util.List)9 IOException (java.io.IOException)6 ConnectionFilter (com.auth0.client.mgmt.filter.ConnectionFilter)5 Auth0Exception (com.auth0.exception.Auth0Exception)5 APIException (com.auth0.exception.APIException)4 RateLimitException (com.auth0.exception.RateLimitException)4 RecordedMultipartRequest (com.auth0.net.multipart.RecordedMultipartRequest)4 JsonParseException (com.fasterxml.jackson.core.JsonParseException)4 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)4 ExpectedException (org.junit.rules.ExpectedException)4 VoidRequest (com.auth0.net.VoidRequest)3 File (java.io.File)3 UsersImportOptions (com.auth0.client.mgmt.filter.UsersImportOptions)2 Job (com.auth0.json.mgmt.jobs.Job)2 User (com.auth0.json.mgmt.users.User)2 FilePart (com.auth0.net.multipart.FilePart)2 KeyValuePart (com.auth0.net.multipart.KeyValuePart)2