Add position id in req body, auto fake remember me
This commit is contained in:
parent
2201d2d9c9
commit
af29569ed5
@ -21,16 +21,16 @@ const aggietime = client.create({
|
|||||||
const replace_path_args = (path, map) =>
|
const replace_path_args = (path, map) =>
|
||||||
path.replaceAll(/:([a-zA-Z0-9_]+)/g, (_, key) => map[key]);
|
path.replaceAll(/:([a-zA-Z0-9_]+)/g, (_, key) => map[key]);
|
||||||
|
|
||||||
const get_user_position_or_specified = async (position) => {
|
const get_user_position_or_specified = async (position_id) => {
|
||||||
const { positions } = await get_user_info();
|
const { positions } = await get_user_info();
|
||||||
|
|
||||||
if (!position && positions.length != 1) {
|
if (position_id === undefined && positions.length != 1) {
|
||||||
throw "Must specify a position when there's not only one to choose from";
|
throw "Must specify a position when there's not only one to choose from";
|
||||||
} else if (!position) {
|
} else if (position_id === undefined) {
|
||||||
position = positions[0];
|
return positions[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return position;
|
return position_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const get_user_info = async () => {
|
export const get_user_info = async () => {
|
||||||
@ -53,12 +53,12 @@ export const get_user_info = async () => {
|
|||||||
return expireCache.get("user");
|
return expireCache.get("user");
|
||||||
};
|
};
|
||||||
|
|
||||||
const do_clock_mutation = async (path, { position } = {}) => {
|
const do_clock_mutation = async (path, { position_id } = {}) => {
|
||||||
position = await get_user_position_or_specified(position);
|
position_id = await get_user_position_or_specified(position_id);
|
||||||
|
|
||||||
return await aggietime
|
return await aggietime
|
||||||
.post(
|
.post(
|
||||||
replace_path_args(path, { position }),
|
replace_path_args(path, { position_id }),
|
||||||
{
|
{
|
||||||
comment: "",
|
comment: "",
|
||||||
},
|
},
|
||||||
@ -74,6 +74,8 @@ const do_clock_mutation = async (path, { position } = {}) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
export const clock_in = async (rest) => do_clock_mutation(CLOCKIN_PATH, rest);
|
export const clock_in = async (rest) => do_clock_mutation(CLOCKIN_PATH, rest);
|
||||||
export const clock_out = async (rest) => do_clock_mutation(CLOCKOUT_PATH, rest);
|
export const clock_out = async (rest) => do_clock_mutation(CLOCKOUT_PATH, rest);
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ export const AGGIETIME_URL_CONTAINS_SIGNIFIES_AUTH_COMPLETE = "employee";
|
|||||||
|
|
||||||
export const REFRESH_JWT_MS = 5 * 1000 * 60;
|
export const REFRESH_JWT_MS = 5 * 1000 * 60;
|
||||||
export const LOGIN_PATH = "api/v1/auth/login";
|
export const LOGIN_PATH = "api/v1/auth/login";
|
||||||
export const CLOCKIN_PATH = "api/v1/positions/:position/clock_in";
|
export const CLOCKIN_PATH = "api/v1/positions/:position_id/clock_in";
|
||||||
export const CLOCKOUT_PATH = "api/v1/positions/:position/clock_out";
|
export const CLOCKOUT_PATH = "api/v1/positions/:position_id/clock_out";
|
||||||
export const USER_PATH = "api/v1/auth/get_user_info";
|
export const USER_PATH = "api/v1/auth/get_user_info";
|
||||||
export const OPEN_SHIFT_PATH = "api/v1/users/:anumber/open_shift";
|
export const OPEN_SHIFT_PATH = "api/v1/users/:anumber/open_shift";
|
||||||
export const OPEN_SHIFT_EXP_SEC = 60;
|
export const OPEN_SHIFT_EXP_SEC = 60;
|
||||||
@ -21,6 +21,8 @@ export const SAML_SUBMIT_SELECTOR = "input[type=submit]";
|
|||||||
export const SAML_EMAIL_SELECTOR = "input[type=email]";
|
export const SAML_EMAIL_SELECTOR = "input[type=email]";
|
||||||
export const SAML_PASSWORD_SELECTOR = "input[type=password]";
|
export const SAML_PASSWORD_SELECTOR = "input[type=password]";
|
||||||
|
|
||||||
|
export const DUO_TRUST_SELECTOR = "#trust-browser-button";
|
||||||
|
|
||||||
export const MAX_DEFAULT_RETRY_AMOUNT = 3;
|
export const MAX_DEFAULT_RETRY_AMOUNT = 3;
|
||||||
export const WAIT_MS = 2000;
|
export const WAIT_MS = 2000;
|
||||||
export const RETRY_EXPONENT = 1.2;
|
export const RETRY_EXPONENT = 1.2;
|
||||||
|
20
src/main.js
20
src/main.js
@ -20,7 +20,7 @@ export default async () => {
|
|||||||
|
|
||||||
if (args.daemon) {
|
if (args.daemon) {
|
||||||
try {
|
try {
|
||||||
start_server(args.socket_path, args.pass_cmd, session.logout);
|
start_server(args, session.logout);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
if (fs.existsSync(args.socket_path)) {
|
if (fs.existsSync(args.socket_path)) {
|
||||||
@ -29,15 +29,17 @@ export default async () => {
|
|||||||
}
|
}
|
||||||
} else if (args.action) {
|
} else if (args.action) {
|
||||||
if (fs.existsSync(args.socket_path)) {
|
if (fs.existsSync(args.socket_path)) {
|
||||||
run_action(args.socket_path, args.action);
|
run_action(args);
|
||||||
} else {
|
} else {
|
||||||
console.error(`ERR: No such socket '${args.socket_path}'`);
|
console.error(`ERR: No such socket '${args.socket_path}'`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const run_action = (socket_path, action) => {
|
const run_action = (args) => {
|
||||||
|
const { socket_path, action, position_id } = args;
|
||||||
const connection = net.connect(socket_path);
|
const connection = net.connect(socket_path);
|
||||||
|
|
||||||
connection.on("data", (data) => {
|
connection.on("data", (data) => {
|
||||||
if (Buffer.isBuffer(data)) {
|
if (Buffer.isBuffer(data)) {
|
||||||
console.log(data.toString().trim());
|
console.log(data.toString().trim());
|
||||||
@ -46,7 +48,8 @@ const run_action = (socket_path, action) => {
|
|||||||
}
|
}
|
||||||
connection.end();
|
connection.end();
|
||||||
});
|
});
|
||||||
connection.write(JSON.stringify({ action }));
|
|
||||||
|
connection.write(JSON.stringify({ action, rest: { position_id } }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const build_args = () => {
|
const build_args = () => {
|
||||||
@ -58,6 +61,11 @@ const build_args = () => {
|
|||||||
default: false,
|
default: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
parser.add_argument("-pos", "--position-id", {
|
||||||
|
help: "Position ID (for usage with --action clock_in or clock_out)",
|
||||||
|
default: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
parser.add_argument("-s", "--socket_path", {
|
parser.add_argument("-s", "--socket_path", {
|
||||||
default: DEFAULT_SOCKET_PATH,
|
default: DEFAULT_SOCKET_PATH,
|
||||||
help: `Set server socket path, defaults to ${DEFAULT_SOCKET_PATH}`,
|
help: `Set server socket path, defaults to ${DEFAULT_SOCKET_PATH}`,
|
||||||
@ -84,7 +92,7 @@ const kill_server = (server, socket_path) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const start_server = async (socket_path, login_cmd, on_exit = () => {}) => {
|
const start_server = async ({ socket_path, pass_cmd }, on_exit = () => {}) => {
|
||||||
if (fs.existsSync(socket_path)) {
|
if (fs.existsSync(socket_path)) {
|
||||||
console.error(
|
console.error(
|
||||||
`ERR: Socket '${socket_path}' already exists.
|
`ERR: Socket '${socket_path}' already exists.
|
||||||
@ -95,7 +103,7 @@ specify another socket path with --socket_path`
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { anumber, password } = await retrieve_creds(login_cmd);
|
const { anumber, password } = await retrieve_creds(pass_cmd);
|
||||||
await session.login(anumber, password);
|
await session.login(anumber, password);
|
||||||
|
|
||||||
session.refresh_jwt();
|
session.refresh_jwt();
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
AGGIETIME_DOMAIN,
|
AGGIETIME_DOMAIN,
|
||||||
AGGIETIME_URI,
|
AGGIETIME_URI,
|
||||||
AGGIETIME_URL_CONTAINS_SIGNIFIES_AUTH_COMPLETE,
|
AGGIETIME_URL_CONTAINS_SIGNIFIES_AUTH_COMPLETE,
|
||||||
|
DUO_TRUST_SELECTOR,
|
||||||
LOGIN_PATH,
|
LOGIN_PATH,
|
||||||
SAML_SIGN_IN_TITLE,
|
SAML_SIGN_IN_TITLE,
|
||||||
SAML_SUBMIT_SELECTOR,
|
SAML_SUBMIT_SELECTOR,
|
||||||
@ -60,9 +61,20 @@ export const login = async (a_number, password) => {
|
|||||||
await new Promise((res) => setTimeout(res, 500));
|
await new Promise((res) => setTimeout(res, 500));
|
||||||
|
|
||||||
console.log("Submit!");
|
console.log("Submit!");
|
||||||
await driver.findElement(By.css(SAML_SUBMIT_SELECTOR)).click();
|
await driver
|
||||||
|
.wait(until.elementLocated(By.css(SAML_SUBMIT_SELECTOR)))
|
||||||
|
.then(() => driver.findElement(By.css(SAML_SUBMIT_SELECTOR)).click());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Press (fake and cringe) "remember me" buttons...');
|
||||||
|
await driver
|
||||||
|
.wait(until.elementLocated(By.css(DUO_TRUST_SELECTOR)))
|
||||||
|
.then(() => driver.findElement(By.css(DUO_TRUST_SELECTOR)).click())
|
||||||
|
.then(() =>
|
||||||
|
driver.wait(until.elementLocated(By.css(SAML_SUBMIT_SELECTOR)))
|
||||||
|
)
|
||||||
|
.then(() => driver.findElement(By.css(SAML_SUBMIT_SELECTOR)).click());
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
"Waiting for aggietime response (potential DUO required here)..."
|
"Waiting for aggietime response (potential DUO required here)..."
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user