Search in sources :

Example 6 with SimpleAuthenticator

use of org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator in project janusgraph by JanusGraph.

the class JanusGraphSimpleAuthenticatorTest method testPassEmptyCredGraphUserIndex.

@Test
public void testPassEmptyCredGraphUserIndex() {
    final JanusGraphSimpleAuthenticator authenticator = createMockBuilder(JanusGraphSimpleAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").createMock();
    final Map<String, Object> configMap = new HashMap<>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_USER, "user");
    final SimpleAuthenticator sa = createMock(SimpleAuthenticator.class);
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final Transaction tx = createMock(Transaction.class);
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(authenticator.createSimpleAuthenticator()).andReturn(sa);
    expect(credentialGraph.findUser("user")).andReturn(null);
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(true);
    expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
    expect(graph.openManagement()).andReturn(mgmt);
    expect(graph.tx()).andReturn(tx);
    sa.setup(configMap);
    EasyMock.expectLastCall();
    graph.close();
    EasyMock.expectLastCall();
    tx.rollback();
    EasyMock.expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) HashMap(java.util.HashMap) SimpleAuthenticator(org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator) JanusGraph(org.janusgraph.core.JanusGraph) Test(org.junit.Test)

Aggregations

SimpleAuthenticator (org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator)6 HashMap (java.util.HashMap)5 CredentialGraph (org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph)5 Transaction (org.apache.tinkerpop.gremlin.structure.Transaction)5 JanusGraph (org.janusgraph.core.JanusGraph)5 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)5 Test (org.junit.Test)5 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 PropertyKey (org.janusgraph.core.PropertyKey)2 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)2 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)2 PropertyKeyMaker (org.janusgraph.core.schema.PropertyKeyMaker)2