File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
String schemaPath = schemaFile.getPath();
schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
VoltProjectBuilder builder = new VoltProjectBuilder();
builder.addSchema(schemaPath);
builder.addPartitionInfo("HELLOWORLD", "DIALECT");
GroupInfo gi = new GroupInfo("foo", true, false, true, true, false, false);
builder.addGroups(new GroupInfo[] { gi } );
// create 20 users, only the first one has an interesting user/pass
UserInfo[] ui = new UserInfo[15];
ui[0] = new UserInfo("ry@nlikesthe", "y@nkees", new String[] { "foo" } );
for (int i = 1; i < ui.length; i++) {
ui[i] = new UserInfo("USER" + String.valueOf(i), "PASS" + String.valueOf(i), new String[] { "foo" } );
}
builder.addUsers(ui);
builder.setSecurityEnabled(true);
ProcedureInfo[] pi = new ProcedureInfo[2];
pi[0] = new ProcedureInfo(new String[] { "foo" }, "Insert", "insert into HELLOWORLD values (?,?,?);", null);
pi[1] = new ProcedureInfo(new String[] { "foo" }, "Select", "select * from HELLOWORLD;", null);
builder.addProcedures(pi);
builder.setHTTPDPort(8095);
boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
assertTrue(success);
VoltDB.Configuration config = new VoltDB.Configuration();
config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
config.m_pathToDeployment = builder.getPathToDeployment();
server = new ServerThread(config);
server.start();
server.waitForInitialization();
ParameterSet pset;
// test good auths
for (UserInfo u : ui) {
pset = ParameterSet.fromArrayNoCopy(u.name, u.password, u.name);
String response = callProcOverJSON("Insert", pset, u.name, u.password, true);
Response r = responseFromJSON(response);
assertEquals(ClientResponse.SUCCESS, r.status);
}
// test re-using auths
for (UserInfo u : ui) {
pset = ParameterSet.fromArrayNoCopy(u.name + "-X", u.password + "-X", u.name + "-X");
String response = callProcOverJSON("Insert", pset, u.name, u.password, false);
Response r = responseFromJSON(response);
assertEquals(ClientResponse.SUCCESS, r.status);
}
// test bad auth
UserInfo u = ui[0];
pset = ParameterSet.fromArrayNoCopy(u.name + "-X1", u.password + "-X1", u.name + "-X1");
String response = callProcOverJSON("Insert", pset, u.name, "ick", true);
Response r = responseFromJSON(response);
assertEquals(ClientResponse.UNEXPECTED_FAILURE, r.status);
response = callProcOverJSON("Insert", pset, u.name, "ick", false);
r = responseFromJSON(response);
assertEquals(ClientResponse.UNEXPECTED_FAILURE, r.status);
// test malformed auth (too short hash)
pset = ParameterSet.fromArrayNoCopy(u.name + "-X2", u.password + "-X2", u.name + "-X2");
String paramsInJSON = pset.toJSONString();
HashMap<String,String> params = new HashMap<String,String>();
params.put("Procedure", "Insert");
params.put("Parameters", paramsInJSON);
params.put("User", u.name);
params.put("Password", Encoder.hexEncode(new byte[] {1,2,3}));
String varString = getHTTPVarString(params);
response = callProcOverJSONRaw(varString, 200);
r = responseFromJSON(response);
assertEquals(ClientResponse.UNEXPECTED_FAILURE, r.status);
// test malformed auth (gibberish password, but good length)
pset = ParameterSet.fromArrayNoCopy(u.name + "-X3", u.password + "-X3", u.name + "-X3");
paramsInJSON = pset.toJSONString();
params = new HashMap<String,String>();
params.put("Procedure", "Insert");
params.put("Parameters", paramsInJSON);
params.put("User", u.name);
params.put("Password", "abcdefghiabcdefghiabcdefghiabcdefghi");
varString = getHTTPVarString(params);
response = callProcOverJSONRaw(varString, 200);
r = responseFromJSON(response);
assertEquals(ClientResponse.UNEXPECTED_FAILURE, r.status);
// the update catalog test below is for enterprise only
if (VoltDB.instance().getConfig().m_isEnterprise == false) {
return;
}
// ENG-963 below here
// do enough to get a new deployment file
VoltProjectBuilder builder2 = new VoltProjectBuilder();
builder2.addSchema(schemaPath);
builder2.addPartitionInfo("HELLOWORLD", "DIALECT");
// Same groups
builder2.addGroups(new GroupInfo[] { gi } );
// create same 15 users, hack the last 14 passwords
ui = new UserInfo[15];
ui[0] = new UserInfo("ry@nlikesthe", "y@nkees", new String[] { "foo" } );
for (int i = 1; i < ui.length; i++) {
ui[i] = new UserInfo("USER" + String.valueOf(i),
"welcomehackers" + String.valueOf(i),
new String[] { "foo" } );
}
builder2.addUsers(ui);
builder2.setSecurityEnabled(true);
builder2.addProcedures(pi);
builder2.setHTTPDPort(8095);
success = builder2.compile(Configuration.getPathToCatalogForTest("json-update.jar"));
assertTrue(success);
pset = ParameterSet.fromArrayNoCopy(Encoder.hexEncode(MiscUtils.fileToBytes(new File(config.m_pathToCatalog))),
new String(MiscUtils.fileToBytes(new File(builder2.getPathToDeployment())), "UTF-8"));
response = callProcOverJSON("@UpdateApplicationCatalog", pset,
ui[0].name, ui[0].password, true);
r = responseFromJSON(response);
assertEquals(ClientResponse.SUCCESS, r.status);