Stoped givin admin-user-helper a PATH. It traverse backwards to find it.

This commit is contained in:
Kræn Hansen 2017-08-14 14:12:00 +02:00
parent d2febaa86d
commit 97800e35b1
2 changed files with 22 additions and 8 deletions

View File

@ -4,9 +4,6 @@ const Jasmine = require("jasmine");
const JasmineConsoleReporter = require('jasmine-console-reporter'); const JasmineConsoleReporter = require('jasmine-console-reporter');
const path = require("path"); const path = require("path");
const ADMIN_TOKEN_PATH = path.resolve(__dirname, "../../../../object-server-for-testing/admin_token.base64");
process.env.ADMIN_TOKEN_PATH = ADMIN_TOKEN_PATH;
const JASMIN_FILTER_KEY = "--filter"; const JASMIN_FILTER_KEY = "--filter";
function getFilterFromProcess() { function getFilterFromProcess() {

View File

@ -7,14 +7,31 @@ let fs = node_require("fs");
let path = node_require("path"); let path = node_require("path");
var Realm = node_require('realm'); var Realm = node_require('realm');
const DEFAULT_ADMIN_TOKEN_PATH = path.join(__dirname, "..", "..", "object-server-for-testing", "admin_token.base64"); function getObjectServerPath() {
const ADMIN_TOKEN_PATH = process.env.ADMIN_TOKEN_PATH || DEFAULT_ADMIN_TOKEN_PATH; const pathParts = __dirname.split(path.sep);
let objectServerPath;
for(let p = pathParts.length; p >= 0; p--) {
const candidatePathParts = pathParts.slice(0, p);
candidatePathParts.push("object-server-for-testing");
const candidatePath = candidatePathParts.join(path.sep);
if (fs.existsSync(candidatePath)) {
return candidatePath;
}
}
return null;
}
function getAdminToken() { function getAdminToken() {
if(fs.existsSync(ADMIN_TOKEN_PATH)) { const objectServerPath = getObjectServerPath();
return fs.readFileSync(ADMIN_TOKEN_PATH, 'utf-8'); if(objectServerPath) {
const accessTokenPath = path.resolve(objectServerPath, "admin_token.base64");
if(fs.existsSync(accessTokenPath)) {
return fs.readFileSync(accessTokenPath, "utf-8");
} else {
throw new Error("Couldn´t locate the admin token, used to access the realm object server.");
}
} else { } else {
throw new Error("Missing the file with an admin token: " + ADMIN_TOKEN_PATH); throw new Error("Couldn´t locate the realm object server.");
} }
} }