use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class UserServiceTest method testRoleOfServiceUserTokenIsAlwaysServiceRole.
@Test
public void testRoleOfServiceUserTokenIsAlwaysServiceRole() {
AccessToken token = service.tokens.issueServiceToken();
ByteBuffer username = service.tokens.identify(token);
Assert.assertEquals(Role.SERVICE, service.getRole(username));
}
use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class ConcourseServerTest method testGetEngineRaceCondition.
@Test
public void testGetEngineRaceCondition() throws TException, InterruptedException {
// CON-673
int port = Networking.getOpenPort();
String env = "test";
String buffer = TestData.getTemporaryTestDir();
String db = TestData.getTemporaryTestDir();
server = ConcourseServer.create(port, buffer, db);
server.spawn();
try {
AccessToken token = server.login(ByteBuffers.fromUtf8String("admin"), ByteBuffers.fromUtf8String("admin"), env);
for (int i = 0; i < 10000; ++i) {
server.addKeyValue(TestData.getSimpleString(), TestData.getTObject(), token, null, env);
}
server.stop();
server = ConcourseServer.create(port, buffer, db);
server.spawn();
int threads = 20;
CountDownLatch latch = new CountDownLatch(threads);
for (int i = 0; i < threads; ++i) {
Thread t = new Thread(() -> {
Concourse client = Concourse.at().port(port).environment(env).connect();
client.exit();
latch.countDown();
});
t.start();
}
latch.await();
Assert.assertEquals(2, server.numEnginesInitialized.get());
} finally {
server.stop();
}
}
use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class ConcourseServerTest method testCommandIsIntrospected.
@Test
public void testCommandIsIntrospected() throws TException, InterruptedException {
server = ConcourseServer.create();
server.spawn();
try {
List<Object> actuals = Lists.newArrayList();
Thread t = new Thread(() -> {
try {
Command.current();
actuals.add(false);
} catch (IllegalStateException e) {
actuals.add(true);
}
try {
AccessToken creds = server.login(ByteBuffer.wrap("admin".getBytes()), ByteBuffer.wrap("admin".getBytes()));
server.addKeyValue("name", Convert.javaToThrift("jeff"), creds, null, "");
actuals.add(Command.current().operation());
server.browseKey("name", creds, null, "");
actuals.add(Command.current().operation());
} catch (TException e) {
e.printStackTrace();
}
});
t.start();
t.join();
Assert.assertTrue((boolean) actuals.get(0));
Assert.assertEquals("add", actuals.get(1));
Assert.assertEquals("browse", actuals.get(2));
} finally {
server.stop();
}
}
use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class UserServiceTest method testAccessTokenIsNotValidIfAccessIsRevoked.
@Test
public void testAccessTokenIsNotValidIfAccessIsRevoked() {
ByteBuffer username = getAcceptableUsername();
ByteBuffer password = getSecurePassword();
service.create(username, password, Role.ADMIN);
AccessToken token = service.tokens.issue(username);
service.delete(username);
Assert.assertFalse(service.tokens.isValid(token));
}
use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class UserServiceTest method testDisablingUserInvalidatesAllAccessTokens.
@Test
public void testDisablingUserInvalidatesAllAccessTokens() {
ByteBuffer username = getAcceptableUsername();
ByteBuffer password = getSecurePassword();
service.create(username, password, Role.ADMIN);
List<AccessToken> tokens = Lists.newArrayList();
for (int i = 0; i < TestData.getScaleCount(); i++) {
tokens.add(service.tokens.issue(username));
}
service.disable(username);
for (AccessToken token : tokens) {
Assert.assertFalse(service.tokens.isValid(token));
}
}
Aggregations