From ef854ce9ea5cd62432afb67bbfcf9b570cd85691 Mon Sep 17 00:00:00 2001 From: sisou Date: Mon, 30 Mar 2020 10:50:06 +0200 Subject: [PATCH 1/4] Improve error for Keyguard iframe with unexpected src --- client/src/RequestBehavior.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/RequestBehavior.ts b/client/src/RequestBehavior.ts index 9eca4fed5..b543d79cd 100644 --- a/client/src/RequestBehavior.ts +++ b/client/src/RequestBehavior.ts @@ -74,8 +74,14 @@ export class IFrameRequestBehavior extends RequestBehavior { } public async request(endpoint: string, command: KeyguardCommand, args: any[]): Promise { - if (this._iframe && this._iframe.src !== `${endpoint}${IFrameRequestBehavior.IFRAME_PATH_SUFFIX}`) { - throw new Error('Keyguard iframe is already opened with another endpoint'); + if (this._iframe + && this._iframe.src + && this._iframe.src !== `${endpoint}${IFrameRequestBehavior.IFRAME_PATH_SUFFIX}` + ) { + const openedSrc = this._iframe.src; + const expectedSrc = `${endpoint}${IFrameRequestBehavior.IFRAME_PATH_SUFFIX}`; + throw new Error('Keyguard iframe is already opened with another endpoint' + + `(opened: ${openedSrc}, expected: ${expectedSrc}`); } const origin = RequestBehavior.getAllowedOrigin(endpoint); From 289745c2565c02915b1ab7375e12a19502beffda Mon Sep 17 00:00:00 2001 From: sisou Date: Fri, 17 Apr 2020 10:02:49 +0200 Subject: [PATCH 2/4] Refactor IFrameRequestBehavior to use a promise for the iframe and client --- client/src/RequestBehavior.ts | 63 ++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/client/src/RequestBehavior.ts b/client/src/RequestBehavior.ts index b543d79cd..804714879 100644 --- a/client/src/RequestBehavior.ts +++ b/client/src/RequestBehavior.ts @@ -64,45 +64,27 @@ export class RedirectRequestBehavior extends RequestBehavior { export class IFrameRequestBehavior extends RequestBehavior { private static IFRAME_PATH_SUFFIX = '/request/iframe/'; - private _iframe: HTMLIFrameElement | null; - private _client: PostMessageRpcClient | null; + private _iframeEndpoint: string | null = null; + private _iframePromise: Promise | null = null; + private _clientPromise: Promise | null = null; constructor() { super(BehaviorType.IFRAME); - this._iframe = null; - this._client = null; } public async request(endpoint: string, command: KeyguardCommand, args: any[]): Promise { - if (this._iframe - && this._iframe.src - && this._iframe.src !== `${endpoint}${IFrameRequestBehavior.IFRAME_PATH_SUFFIX}` - ) { - const openedSrc = this._iframe.src; - const expectedSrc = `${endpoint}${IFrameRequestBehavior.IFRAME_PATH_SUFFIX}`; - throw new Error('Keyguard iframe is already opened with another endpoint' + - `(opened: ${openedSrc}, expected: ${expectedSrc}`); - } - - const origin = RequestBehavior.getAllowedOrigin(endpoint); - - if (!this._iframe) { - this._iframe = await this.createIFrame(endpoint); - } - if (!this._iframe.contentWindow) { - throw new Error(`IFrame contentWindow is ${typeof this._iframe.contentWindow}`); - } - - if (!this._client) { - this._client = new PostMessageRpcClient(this._iframe.contentWindow, origin); - await this._client.init(); - } - - return await this._client.call(command, ...args); + const client = await this._getClient(endpoint); + return client.call(command, ...args); } public async createIFrame(endpoint: string): Promise { - return new Promise((resolve, reject) => { + if (this._iframeEndpoint && this._iframeEndpoint !== endpoint) { + throw new Error('Keyguard iframe is already opened with another endpoint' + + `(opened: ${this._iframeEndpoint}, expected: ${endpoint})`); + } + this._iframeEndpoint = endpoint; + + this._iframePromise = this._iframePromise || new Promise((resolve, reject) => { const $iframe = document.createElement('iframe'); $iframe.name = 'NimiqKeyguardIFrame'; $iframe.style.display = 'none'; @@ -110,6 +92,25 @@ export class IFrameRequestBehavior extends RequestBehavior { $iframe.src = `${endpoint}${IFrameRequestBehavior.IFRAME_PATH_SUFFIX}`; $iframe.onload = () => resolve($iframe); $iframe.onerror = reject; - }) as Promise; + }); + + return this._iframePromise; + } + + private _getClient(endpoint: string): Promise { + this._clientPromise = this._clientPromise || new Promise(async (resolve) => { + const iframe = await this.createIFrame(endpoint); + if (!iframe.contentWindow) { + throw new Error(`IFrame contentWindow is ${typeof iframe.contentWindow}`); + } + + const origin = RequestBehavior.getAllowedOrigin(endpoint); + const client = new PostMessageRpcClient(iframe.contentWindow, origin); + await client.init(); + + resolve(client); + }); + + return this._clientPromise; } } From cb5fffe5add4ab8069b68faa106f75c0ac987e7a Mon Sep 17 00:00:00 2001 From: Curd Becker Date: Sat, 13 Jun 2020 23:18:28 +0200 Subject: [PATCH 3/4] Add private CI for Gitlab --- .gitlab-ci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..d014c4014 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,40 @@ +stages: + - build + - test + - docker + - deploy + +# include private configs for the remaining stages +include: + - project: "it/ci-config" + file: "/testnet/deploy_webapp.yml" + +build: + stage: build + image: node:lts + artifacts: + paths: + - dist/ + cache: + key: node-cache + paths: + - node_modules/ + script: + - yarn install + - yarn build + # Make sure the dist directory exists, so that _this_ job fails and not the next one + - test -d dist || (echo "No dist directory\!" && exit 1) + - test -f dist/index.html || (echo "No files in dist\!" && exit 1) + allow_failure: false + +test: + stage: test + image: node:lts + cache: + key: node-cache + paths: + - node_modules/ + script: + - yarn lint + allow_failure: true + From 778b529509cbd6da87172295b14dcd95f0d15ebb Mon Sep 17 00:00:00 2001 From: Curd Becker Date: Mon, 15 Jun 2020 17:01:37 +0200 Subject: [PATCH 4/4] Migrate nginx config from private config into public one --- .gitlab-ci.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d014c4014..e8f192171 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,6 +9,21 @@ include: - project: "it/ci-config" file: "/testnet/deploy_webapp.yml" +variables: + # nginx configuration for this webapp + NGINX_CONFIG: | + server { + listen 80; + listen [::]:80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $$uri $$uri/ =404; + } + } + build: stage: build image: node:lts