Skip to content

Commit

Permalink
feat(oauth): remove keytar dependencies (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
olamothe authored Mar 29, 2021
1 parent 68d3052 commit ee876e6
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 246 deletions.
3 changes: 0 additions & 3 deletions packages/cli-e2e/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ RUN apt-get install -y libncurses5-dev libncursesw5-dev xz-utils tk-dev
# For headless without headless.
RUN apt-get install xvfb -y

# For Keytar see: https://github.com/atom/node-keytar#on-linux
RUN apt-get install -y libsecret-1-dev

# cp but better (need filtering abilities)
RUN apt-get install -y rsync
# sudo for running the test as not root while still being root.
Expand Down
39 changes: 39 additions & 0 deletions packages/cli-e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/cli-e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
"test:headless": "node ./entrypoints/entry.js",
"test:debug": "node ./entrypoints/entry.js --debug",
"test:bash": "node ./entrypoints/entry.js --bash",
"jest": "jest",
"jest": "jest --verbose",
"jest:debug": "node --inspect=0.0.0.0:9229 node_modules/.bin/jest --runInBand"
},
"bugs": {
"url": "https://github.com/coveo/cli/issues"
},
"devDependencies": {
"@types/async-retry": "1.4.2",
"@types/jest": "26.0.20",
"keytar": "^7.4.0"
"@types/fs-extra": "^9.0.9",
"@types/jest": "26.0.20"
},
"dependencies": {
"@babel/core": "7.12.17",
Expand All @@ -38,8 +38,8 @@
"async-retry": "1.3.1",
"axios": "^0.21.1",
"babel-jest": "26.6.3",
"fs-extra": "^9.1.0",
"jest": "26.6.3",
"keytar": "^7.4.0",
"puppeteer": "^8.0.0",
"strip-ansi": "^6.0.0",
"typescript": "4.1.5"
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-e2e/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
connectToChromeBrowser,
SCREENSHOTS_PATH,
} from './utils/browser';
import {clearKeychain, loginWithOffice} from './utils/login';
import {clearAccessTokenFromConfig, loginWithOffice} from './utils/login';

declare global {
namespace NodeJS {
Expand All @@ -33,7 +33,7 @@ export default async function () {
mkdirSync(SCREENSHOTS_PATH, {recursive: true});
const browser = await connectToChromeBrowser();
await clearChromeBrowsingData(browser);
await clearKeychain();
await clearAccessTokenFromConfig();
try {
global.loginProcess = await loginWithOffice();
} catch (e) {
Expand Down
28 changes: 17 additions & 11 deletions packages/cli-e2e/utils/login.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import retry from 'async-retry';
import {deletePassword, getPassword} from 'keytar';
import {userInfo} from 'os';
import type {Browser, Page, Target} from 'puppeteer';
import {spawn} from 'child_process';
import {answerPrompt, CLI_EXEC_PATH, isYesNoPrompt} from './cli';
import LoginSelectors from './loginSelectors';
import {strictEqual} from 'assert';
import {connectToChromeBrowser} from './browser';
import {isElementClickable} from './browser';
import {readJSON, writeJSON, existsSync} from 'fs-extra';

function isLoginPage(page: Page) {
// TODO: CDX-98: URL should vary in fonction of the targeted environment.
return page.url() === 'https://platformdev.cloud.coveo.com/login';
}

export async function isLoggedin() {
const currentAccount = userInfo().username;
const accessToken = await getPassword(
'com.coveo.cli.access.token',
currentAccount
);
return Boolean(accessToken);
if (!existsSync(getConfigFilePath())) {
return false;
}
const cfg = await readJSON(getConfigFilePath());
return Boolean(cfg.accessToken);
}

function waitForLoginPage(browser: Browser) {
Expand Down Expand Up @@ -123,7 +121,15 @@ export async function loginWithOffice() {
return loginProcess;
}

export async function clearKeychain() {
const currentAccount = userInfo().username;
await deletePassword('com.coveo.cli.access.token', currentAccount);
export async function clearAccessTokenFromConfig() {
if (!existsSync(getConfigFilePath())) {
return;
}
const cfg = await readJSON(getConfigFilePath());
delete cfg.accessToken;
await writeJSON(getConfigFilePath(), cfg);
}

function getConfigFilePath() {
return '/home/notGroot/.config/@coveo/cli/config.json';
}
Loading

0 comments on commit ee876e6

Please sign in to comment.