Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): Don't use dgraph binary in tests (GRAPHQL-1144) #168

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ dependencies {
testCompile "io.opencensus:opencensus-exporter-trace-jaeger:${openCensusVersion}"
testRuntime "io.opencensus:opencensus-impl:${openCensusVersion}"

// Used for unmarshalling a JSON GraphQL response
testCompile "com.google.code.gson:gson:2.8.6"

// Declare the dependency for your favourite test framework you want to use in your tests.
testCompile 'org.testng:testng:6.8.8'
// javax.annotation is removed from the oracle java se 11, and requires explicit dependency
Expand Down
156 changes: 11 additions & 145 deletions src/test/java/io/dgraph/AclTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.grpc.StatusRuntimeException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import org.testng.annotations.BeforeClass;
Expand All @@ -16,16 +15,13 @@
public class AclTest extends DgraphIntegrationTest {
private static final String USER_ID = "alice";
private static final String USER_PASSWORD = "simplepassword";
private static final String GUARDIAN_CREDS = "user=groot;password=password;namespace=0";
private static final String PREDICATE_TO_READ = "predicate_to_read";
private static final String PREDICATE_TO_WRITE = "predicate_to_write";
private static final String PREDICATE_TO_ALTER = "predicate_to_alter";
private static final String QUERY_ATTR = "name";
private static final String UNUSED_GROUP = "unusedGroup";
private static final String DEV_GROUP = "dev";

private static final String DGRAPH_ENDPOINT = TEST_HOSTNAME + ":" + TEST_PORT;

@BeforeClass
public void setSchema() {
dgraphClient.alter(
Expand Down Expand Up @@ -88,119 +84,28 @@ private void createAccountAndData() throws Exception {
.build());
}

private void createGroupAndACLs(String group, boolean addUserToGroup)
throws IOException, InterruptedException {
private void createGroupAndACLs(String group, boolean addUserToGroup) throws Exception {

// create a new group
checkCmd(
"unable to create the group " + group,
"dgraph",
"acl",
"add",
"-a",
DGRAPH_ENDPOINT,
"-g",
group,
"--guardian-creds",
GUARDIAN_CREDS);
TestUtil.addGroup(group);

if (addUserToGroup) {
checkCmd(
"unable to add user " + USER_ID + " to the group " + group,
"dgraph",
"acl",
"mod",
"-a",
DGRAPH_ENDPOINT,
"-u",
USER_ID,
"--group_list",
group,
"--guardian-creds",
GUARDIAN_CREDS);
TestUtil.updateUser(USER_ID, group, true);
}

// add READ permission on the predicate_to_read to the group
checkCmd(
"unable to add READ permission on " + PREDICATE_TO_READ + " to the group " + group,
"dgraph",
"acl",
"mod",
"-a",
DGRAPH_ENDPOINT,
"-g",
group,
"-p",
PREDICATE_TO_READ,
"-m",
"4",
"--guardian-creds",
GUARDIAN_CREDS);
TestUtil.updateGroup(group, PREDICATE_TO_READ, 4);

// also add READ permission on the attribute queryAttr, which is used inside the query block
checkCmd(
"unable to add READ permission on " + QUERY_ATTR + " to the group " + group,
"dgraph",
"acl",
"mod",
"-a",
DGRAPH_ENDPOINT,
"-g",
group,
"-p",
QUERY_ATTR,
"-m",
"4",
"--guardian-creds",
GUARDIAN_CREDS);
TestUtil.updateGroup(group, QUERY_ATTR, 4);

checkCmd(
"unable to add WRITE permission on " + PREDICATE_TO_WRITE + " to the group " + group,
"dgraph",
"acl",
"mod",
"-a",
DGRAPH_ENDPOINT,
"-g",
group,
"-p",
PREDICATE_TO_WRITE,
"-m",
"2",
"--guardian-creds",
GUARDIAN_CREDS);
TestUtil.updateGroup(group, PREDICATE_TO_WRITE, 2);

checkCmd(
"unable to add ALTER permission on " + PREDICATE_TO_ALTER + " to the group " + group,
"dgraph",
"acl",
"mod",
"-a",
DGRAPH_ENDPOINT,
"-g",
group,
"-p",
PREDICATE_TO_ALTER,
"-m",
"1",
"--guardian-creds",
GUARDIAN_CREDS);
TestUtil.updateGroup(group, PREDICATE_TO_ALTER, 1);
}

private void removeUserFromAllGroups() throws IOException, InterruptedException {
checkCmd(
"unable to remove user " + USER_ID + " from all the groups",
"dgraph",
"acl",
"mod",
"-a",
DGRAPH_ENDPOINT,
"-u",
USER_ID,
"--group_list",
"",
"--guardian-creds",
GUARDIAN_CREDS);
private void removeUserFromAllGroups() throws Exception {
TestUtil.updateUser(USER_ID, DEV_GROUP, false);
}

private void queryPredicateWithUserAccount(boolean shouldFail) {
Expand Down Expand Up @@ -278,47 +183,8 @@ private void verifyOperation(boolean shouldFail, String operation, Runnable runn
}

private void resetUser() throws Exception {
Process deleteUserCmd =
new ProcessBuilder(
"dgraph",
"acl",
"del",
"-a",
DGRAPH_ENDPOINT,
"-u",
USER_ID,
"--guardian-creds",
GUARDIAN_CREDS)
.start();
deleteUserCmd.waitFor();

Process createUserCmd =
new ProcessBuilder(
"dgraph",
"acl",
"add",
"-a",
DGRAPH_ENDPOINT,
"-u",
USER_ID,
"-p",
USER_PASSWORD,
"--guardian-creds",
GUARDIAN_CREDS)
.redirectErrorStream(true)
.start();
createUserCmd.waitFor();
if (createUserCmd.exitValue() != 0) {
// print out the output from the command
InputStream inputStream = createUserCmd.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}

throw new Exception("unable to create user");
}
TestUtil.deleteUser(USER_ID);
TestUtil.addUser(USER_ID, USER_PASSWORD);
}

private void checkCmd(String failureMsg, String... args)
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/io/dgraph/DgraphIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
public abstract class DgraphIntegrationTest {
static final Logger logger = LoggerFactory.getLogger(DgraphIntegrationTest.class);
static final String TEST_HOSTNAME = "localhost";
static final int TEST_PORT = 9180;
static final int TEST_gRPC_PORT = 9180;
static final int TEST_HTTP_PORT = 8180;
protected static DgraphClient dgraphClient;
private static ManagedChannel channel1, channel2, channel3;

Expand Down
Loading