Skip to content

Commit

Permalink
Merge pull request #6 from gemini-testing/rebranding
Browse files Browse the repository at this point in the history
chore: hermione -> testplane
  • Loading branch information
KuznetsovRoman authored Apr 8, 2024
2 parents 1d299e3 + 6c25963 commit 1fe7ca4
Show file tree
Hide file tree
Showing 8 changed files with 3,849 additions and 1,388 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [14.x, 16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v2
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# hermione-oauth
# @testplane/oauth

Some Remote WebDriver Servers requires OAuth authorization for each request. This plugin is useful for setting of authorization header with OAuth token.

## Install

```bash
npm install hermione-oauth --save-dev
npm install @testplane/oauth --save-dev
```

## Usage

```js
// .hermione.conf.js
// .testplane.conf.js
module.exports = {
// ...
plugins: {
"hermione-oauth": {
"@testplane/oauth": {
enabled: true, // plugin is enabled by default
token: "<token>", // option also accepts absolute filepath with a token
help: "https://...", // information on where to get a token
Expand All @@ -25,5 +25,5 @@ module.exports = {
```

Each plugin option can be redefined by
- environment variable which starts with prefix `hermione_oauth_`, for example, `hermione_oauth_token=123-456-789`
- environment variable which starts with prefix `testplane_oauth_`, for example, `testplane_oauth_token=123-456-789`
- CLI option which starts with prefix `--oauth-`, for example, `--oauth-token=123-456-789`
5,143 changes: 3,801 additions & 1,342 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hermione-oauth",
"version": "2.0.0",
"name": "@testplane/oauth",
"version": "0.0.1",
"description": "Plugin for convenient setting of authorization header with OAuth token",
"main": "build/index.js",
"files": [
Expand All @@ -21,39 +21,38 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/gemini-testing/hermione-oauth.git"
"url": "git+https://github.com/gemini-testing/testplane-oauth.git"
},
"engines": {
"node": ">= 12.0.0"
},
"keywords": [
"testplane",
"hermione",
"plugin",
"oauth"
],
"license": "UNLICENSED",
"bugs": {
"url": "https://github.com/gemini-testing/hermione-oauth/issues"
"url": "https://github.com/gemini-testing/testplane-oauth/issues"
},
"homepage": "https://github.com/gemini-testing/hermione-oauth#readme",
"homepage": "https://github.com/gemini-testing/testplane-oauth#readme",
"devDependencies": {
"@types/jest": "28.1.3",
"@types/node": "12.20.55",
"@typescript-eslint/eslint-plugin": "5.30.0",
"@typescript-eslint/parser": "5.30.0",
"eslint": "8.18.0",
"eslint-config-gemini-testing": "3.0.0",
"hermione": "5.0.1",
"jest": "28.1.1",
"jest-extended": "2.0.0",
"prettier": "2.7.1",
"rimraf": "3.0.2",
"testplane": "0.1.0-rc.0",
"ts-jest": "28.0.5",
"typescript": "4.7.4"
},
"dependencies": {
"gemini-configparser": "1.3.0"
},
"peerDependencies": {
"hermione": ">=3.13.0"
}
}
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function parseConfig(options: Record<string, unknown>): PluginConfig {
}),
help: nonEmptyString("help"),
}),
{ envPrefix: "hermione_oauth_", cliPrefix: "--oauth-" },
{ envPrefix: "testplane_oauth_", cliPrefix: "--oauth-" },
);

return parseOptions({ options, env, argv });
Expand Down
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class PluginError extends Error {
constructor(message: string) {
super(`hermione-oauth: ${message}`);
super(`@testplane/oauth: ${message}`);
}
}

Expand Down
51 changes: 27 additions & 24 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,68 @@
import { EventEmitter } from "events";

import type Hermione from "hermione";
import type Testplane from "testplane";
import type { Config } from "testplane";

import plugin from "./";
import * as readToken from "./read-token";

type BrowserConfig = Config["browsers"][string];

jest.mock("./config", () => ({ parseConfig: jest.fn(opts => opts) }));

jest.mock("./read-token");
const readTokenMock = readToken as jest.Mocked<typeof readToken>;

describe("hermione-oauth", () => {
const browser = (config: object = {}): Hermione.BrowserConfig => config as unknown as Hermione.BrowserConfig;
describe("@testplane/oauth", () => {
const browser = (config: object = {}): BrowserConfig => config as unknown as BrowserConfig;

const hermioneMock = (browsers: Record<string, Hermione.BrowserConfig>): Hermione => {
const emitter = new EventEmitter() as unknown as Hermione;
const testplaneMock = (browsers: Record<string, BrowserConfig>): Testplane => {
const emitter = new EventEmitter() as any;

emitter.events = { BEGIN: "begin" } as Hermione.EVENTS;
emitter.events = { BEGIN: "begin" }
emitter.config = {
forBrowser: (id: string) => browsers[id],
getBrowserIds: () => Object.keys(browsers),
} as Hermione.Config;
} as Config;

return emitter;
};

test("should do nothing if plugin is disabled", () => {
const config = { headers: { "<foo>": "<bar>" } };
const hermione = hermioneMock({ "<bro-id>": browser(config) });
const testplane = testplaneMock({ "<bro-id>": browser(config) });

plugin(hermione, { enabled: false });
hermione.emit(hermione.events.BEGIN);
plugin(testplane, { enabled: false });
testplane.emit(testplane.events.BEGIN);

expect(config).toEqual({ headers: { "<foo>": "<bar>" } });
});

test("should set token for each browser config", () => {
const [config1, config2] = [{ headers: { "<foo>": "<bar>" } }, { headers: { "<baz>": "<quux>" } }];
const hermione = hermioneMock({ "<bro1-id>": browser(config1), "<bro2-id>": browser(config2) });
const testplane = testplaneMock({ "<bro1-id>": browser(config1), "<bro2-id>": browser(config2) });

plugin(hermione, { enabled: true, token: "123456789" });
hermione.emit(hermione.events.BEGIN);
plugin(testplane, { enabled: true, token: "123456789" });
testplane.emit(testplane.events.BEGIN);

expect(config1).toEqual({ headers: { "<foo>": "<bar>", Authorization: "OAuth 123456789" } });
expect(config2).toEqual({ headers: { "<baz>": "<quux>", Authorization: "OAuth 123456789" } });
});

test("should not set token if authorization header is already set", () => {
const config = { headers: { Authorization: "<foo>" } };
const hermione = hermioneMock({ "<bro-id>": browser(config) });
const testplane = testplaneMock({ "<bro-id>": browser(config) });

plugin(hermione, { enabled: true, token: "123456789" });
hermione.emit(hermione.events.BEGIN);
plugin(testplane, { enabled: true, token: "123456789" });
testplane.emit(testplane.events.BEGIN);

expect(config).toEqual({ headers: { Authorization: "<foo>" } });
});

test("should read token from file when it is given as absolute path", () => {
const hermione = hermioneMock({ "<bro-id>": browser() });
const testplane = testplaneMock({ "<bro-id>": browser() });

plugin(hermione, { enabled: true, token: "/foo/bar", help: "https://<help>" });
plugin(testplane, { enabled: true, token: "/foo/bar", help: "https://<help>" });

expect(readTokenMock.default).toHaveBeenCalledTimes(1);
expect(readTokenMock.default).toHaveBeenCalledWith("/foo/bar", "https://<help>");
Expand All @@ -69,10 +72,10 @@ describe("hermione-oauth", () => {
readTokenMock.default.mockReturnValue("987654321");

const [config1, config2] = [{ headers: { "<foo>": "<bar>" } }, { headers: { "<baz>": "<quux>" } }];
const hermione = hermioneMock({ "<bro1-id>": browser(config1), "<bro2-id>": browser(config2) });
const testplane = testplaneMock({ "<bro1-id>": browser(config1), "<bro2-id>": browser(config2) });

plugin(hermione, { enabled: true, token: "/foo/bar" });
hermione.emit(hermione.events.BEGIN);
plugin(testplane, { enabled: true, token: "/foo/bar" });
testplane.emit(testplane.events.BEGIN);

expect(config1).toEqual({ headers: { "<foo>": "<bar>", Authorization: "OAuth 987654321" } });
expect(config2).toEqual({ headers: { "<baz>": "<quux>", Authorization: "OAuth 987654321" } });
Expand All @@ -82,11 +85,11 @@ describe("hermione-oauth", () => {
readTokenMock.default.mockReturnValue("987654321");

const config = { headers: { Authorization: "<foo>" } };
const hermione = hermioneMock({ "<bro-id>": browser(config) });
const testplane = testplaneMock({ "<bro-id>": browser(config) });

plugin(hermione, { enabled: true, token: "/foo/bar" });
plugin(testplane, { enabled: true, token: "/foo/bar" });

hermione.emit(hermione.events.BEGIN);
testplane.emit(testplane.events.BEGIN);

expect(config).toEqual({ headers: { Authorization: "<foo>" } });
});
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from "path";

import type Hermione from "hermione";
import type Testplane from "testplane";

import { parseConfig } from "./config";
import readToken from "./read-token";

export = (hermione: Hermione, options: Record<string, unknown>): void => {
export = (testplane: Testplane, options: Record<string, unknown>): void => {
const config = parseConfig(options);

if (!config.enabled) {
Expand All @@ -14,9 +14,9 @@ export = (hermione: Hermione, options: Record<string, unknown>): void => {

const token = path.isAbsolute(config.token) ? readToken(config.token, config.help) : config.token;

hermione.on(hermione.events.BEGIN, () => {
hermione.config.getBrowserIds().forEach(browserId => {
const browserConfig = hermione.config.forBrowser(browserId);
testplane.on(testplane.events.BEGIN, () => {
testplane.config.getBrowserIds().forEach(browserId => {
const browserConfig = testplane.config.forBrowser(browserId);

browserConfig.headers = { Authorization: `OAuth ${token}`, ...browserConfig.headers };
});
Expand Down

0 comments on commit 1fe7ca4

Please sign in to comment.