refactor(aio): use dedicated `constants.ts` file for e2e-specific constants
This commit is contained in:
parent
9e1b61326c
commit
11647e4c78
|
@ -0,0 +1,10 @@
|
||||||
|
// Using the values below, we can fake the response of the corresponding methods in tests. This is
|
||||||
|
// necessary, because the test upload-server will be running as a separate node process, so we will
|
||||||
|
// not have direct access to the code (e.g. for mocking).
|
||||||
|
// (See also 'lib/verify-setup/start-test-upload-server.ts'.)
|
||||||
|
|
||||||
|
// Special values to be used as `authHeader` in `BuildVerifier#verify()`.
|
||||||
|
/* tslint:disable: variable-name */
|
||||||
|
export const BV_verify_error = 'FAKE_VERIFICATION_ERROR';
|
||||||
|
export const BV_verify_verifiedNotTrusted = 'FAKE_VERIFIED_NOT_TRUSTED';
|
||||||
|
/* tslint:enable: variable-name */
|
|
@ -1,5 +1,6 @@
|
||||||
// Imports
|
// Imports
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as c from './constants';
|
||||||
import {helper as h} from './helper';
|
import {helper as h} from './helper';
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
|
@ -14,9 +15,6 @@ h.runForAllSupportedSchemes((scheme, port) => describe(`integration (on ${scheme
|
||||||
const getFile = (pr: string, sha: string, file: string) =>
|
const getFile = (pr: string, sha: string, file: string) =>
|
||||||
h.runCmd(`curl -iL ${scheme}://pr${pr}-${h.getShordSha(sha)}.${host}/${file}`);
|
h.runCmd(`curl -iL ${scheme}://pr${pr}-${h.getShordSha(sha)}.${host}/${file}`);
|
||||||
const uploadBuild = (pr: string, sha: string, archive: string, authHeader = 'Token FOO') => {
|
const uploadBuild = (pr: string, sha: string, archive: string, authHeader = 'Token FOO') => {
|
||||||
// Using `FAKE_VERIFICATION_ERROR` or `FAKE_VERIFIED_NOT_TRUSTED` as `authHeader`,
|
|
||||||
// we can fake the response of the overwritten `BuildVerifier.verify()` method.
|
|
||||||
// (See 'lib/upload-server/index-test.ts'.)
|
|
||||||
const curlPost = `curl -iLX POST --header "Authorization: ${authHeader}"`;
|
const curlPost = `curl -iLX POST --header "Authorization: ${authHeader}"`;
|
||||||
return h.runCmd(`${curlPost} --data-binary "@${archive}" ${scheme}://${host}/create-build/${pr}/${sha}`);
|
return h.runCmd(`${curlPost} --data-binary "@${archive}" ${scheme}://${host}/create-build/${pr}/${sha}`);
|
||||||
};
|
};
|
||||||
|
@ -54,7 +52,7 @@ h.runForAllSupportedSchemes((scheme, port) => describe(`integration (on ${scheme
|
||||||
|
|
||||||
h.createDummyArchive(pr9, sha9, archivePath);
|
h.createDummyArchive(pr9, sha9, archivePath);
|
||||||
|
|
||||||
uploadBuild(pr9, sha9, archivePath, 'FAKE_VERIFIED_NOT_TRUSTED').
|
uploadBuild(pr9, sha9, archivePath, c.BV_verify_verifiedNotTrusted).
|
||||||
then(() => Promise.all([
|
then(() => Promise.all([
|
||||||
getFile(pr9, sha9, 'index.html').then(h.verifyResponse(404)),
|
getFile(pr9, sha9, 'index.html').then(h.verifyResponse(404)),
|
||||||
getFile(pr9, sha9, 'foo/bar.js').then(h.verifyResponse(404)),
|
getFile(pr9, sha9, 'foo/bar.js').then(h.verifyResponse(404)),
|
||||||
|
@ -74,7 +72,7 @@ h.runForAllSupportedSchemes((scheme, port) => describe(`integration (on ${scheme
|
||||||
|
|
||||||
h.createDummyArchive(pr9, sha9, archivePath);
|
h.createDummyArchive(pr9, sha9, archivePath);
|
||||||
|
|
||||||
uploadBuild(pr9, sha9, archivePath, 'FAKE_VERIFICATION_ERROR').
|
uploadBuild(pr9, sha9, archivePath, c.BV_verify_error).
|
||||||
then(h.verifyResponse(403, errorRegex9)).
|
then(h.verifyResponse(403, errorRegex9)).
|
||||||
then(() => {
|
then(() => {
|
||||||
expect(h.buildExists(pr9)).toBe(false);
|
expect(h.buildExists(pr9)).toBe(false);
|
||||||
|
@ -123,7 +121,7 @@ h.runForAllSupportedSchemes((scheme, port) => describe(`integration (on ${scheme
|
||||||
h.createDummyBuild(pr9, sha0, false);
|
h.createDummyBuild(pr9, sha0, false);
|
||||||
h.createDummyArchive(pr9, sha9, archivePath);
|
h.createDummyArchive(pr9, sha9, archivePath);
|
||||||
|
|
||||||
uploadBuild(pr9, sha9, archivePath, 'FAKE_VERIFIED_NOT_TRUSTED').
|
uploadBuild(pr9, sha9, archivePath, c.BV_verify_verifiedNotTrusted).
|
||||||
then(() => Promise.all([
|
then(() => Promise.all([
|
||||||
getFile(pr9, sha0, 'index.html').then(h.verifyResponse(404)),
|
getFile(pr9, sha0, 'index.html').then(h.verifyResponse(404)),
|
||||||
getFile(pr9, sha0, 'foo/bar.js').then(h.verifyResponse(404)),
|
getFile(pr9, sha0, 'foo/bar.js').then(h.verifyResponse(404)),
|
||||||
|
@ -148,7 +146,7 @@ h.runForAllSupportedSchemes((scheme, port) => describe(`integration (on ${scheme
|
||||||
h.createDummyBuild(pr9, sha0);
|
h.createDummyBuild(pr9, sha0);
|
||||||
h.createDummyArchive(pr9, sha9, archivePath);
|
h.createDummyArchive(pr9, sha9, archivePath);
|
||||||
|
|
||||||
uploadBuild(pr9, sha9, archivePath, 'FAKE_VERIFICATION_ERROR').
|
uploadBuild(pr9, sha9, archivePath, c.BV_verify_error).
|
||||||
then(h.verifyResponse(403, errorRegex9)).
|
then(h.verifyResponse(403, errorRegex9)).
|
||||||
then(() => {
|
then(() => {
|
||||||
expect(h.buildExists(pr9)).toBe(true);
|
expect(h.buildExists(pr9)).toBe(true);
|
||||||
|
@ -186,7 +184,7 @@ h.runForAllSupportedSchemes((scheme, port) => describe(`integration (on ${scheme
|
||||||
h.createDummyBuild(pr9, sha9, false);
|
h.createDummyBuild(pr9, sha9, false);
|
||||||
h.createDummyArchive(pr9, sha9, archivePath);
|
h.createDummyArchive(pr9, sha9, archivePath);
|
||||||
|
|
||||||
uploadBuild(pr9, sha9, archivePath, 'FAKE_VERIFIED_NOT_TRUSTED').
|
uploadBuild(pr9, sha9, archivePath, c.BV_verify_verifiedNotTrusted).
|
||||||
then(h.verifyResponse(409)).
|
then(h.verifyResponse(409)).
|
||||||
then(() => {
|
then(() => {
|
||||||
expect(h.readBuildFile(pr9, sha9, 'index.html', false)).toMatch(idxContentRegex9);
|
expect(h.readBuildFile(pr9, sha9, 'index.html', false)).toMatch(idxContentRegex9);
|
||||||
|
|
|
@ -2,16 +2,17 @@
|
||||||
import {GithubPullRequests} from '../common/github-pull-requests';
|
import {GithubPullRequests} from '../common/github-pull-requests';
|
||||||
import {BUILD_VERIFICATION_STATUS, BuildVerifier} from '../upload-server/build-verifier';
|
import {BUILD_VERIFICATION_STATUS, BuildVerifier} from '../upload-server/build-verifier';
|
||||||
import {UploadError} from '../upload-server/upload-error';
|
import {UploadError} from '../upload-server/upload-error';
|
||||||
|
import * as c from './constants';
|
||||||
|
|
||||||
// Run
|
// Run
|
||||||
// TODO(gkalpak): Add e2e tests to cover these interactions as well.
|
// TODO(gkalpak): Add e2e tests to cover these interactions as well.
|
||||||
GithubPullRequests.prototype.addComment = () => Promise.resolve();
|
GithubPullRequests.prototype.addComment = () => Promise.resolve();
|
||||||
BuildVerifier.prototype.verify = (expectedPr: number, authHeader: string) => {
|
BuildVerifier.prototype.verify = (expectedPr: number, authHeader: string) => {
|
||||||
switch (authHeader) {
|
switch (authHeader) {
|
||||||
case 'FAKE_VERIFICATION_ERROR':
|
case c.BV_verify_error:
|
||||||
// For e2e tests, fake a verification error.
|
// For e2e tests, fake a verification error.
|
||||||
return Promise.reject(new UploadError(403, `Error while verifying upload for PR ${expectedPr}: Test`));
|
return Promise.reject(new UploadError(403, `Error while verifying upload for PR ${expectedPr}: Test`));
|
||||||
case 'FAKE_VERIFIED_NOT_TRUSTED':
|
case c.BV_verify_verifiedNotTrusted:
|
||||||
// For e2e tests, fake a `verifiedNotTrusted` verification status.
|
// For e2e tests, fake a `verifiedNotTrusted` verification status.
|
||||||
return Promise.resolve(BUILD_VERIFICATION_STATUS.verifiedNotTrusted);
|
return Promise.resolve(BUILD_VERIFICATION_STATUS.verifiedNotTrusted);
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Imports
|
// Imports
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as c from './constants';
|
||||||
import {CmdResult, helper as h} from './helper';
|
import {CmdResult, helper as h} from './helper';
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
|
@ -63,7 +64,7 @@ describe('upload-server (on HTTP)', () => {
|
||||||
|
|
||||||
|
|
||||||
it('should reject requests for which the PR verification fails', done => {
|
it('should reject requests for which the PR verification fails', done => {
|
||||||
const headers = `--header "Authorization: FAKE_VERIFICATION_ERROR" ${xFileHeader}`;
|
const headers = `--header "Authorization: ${c.BV_verify_error}" ${xFileHeader}`;
|
||||||
const url = `http://${host}/create-build/${pr}/${sha9}`;
|
const url = `http://${host}/create-build/${pr}/${sha9}`;
|
||||||
const bodyRegex = new RegExp(`Error while verifying upload for PR ${pr}: Test`);
|
const bodyRegex = new RegExp(`Error while verifying upload for PR ${pr}: Test`);
|
||||||
|
|
||||||
|
@ -107,7 +108,7 @@ describe('upload-server (on HTTP)', () => {
|
||||||
|
|
||||||
[true, false].forEach(isPublic => describe(`(for ${isPublic ? 'public' : 'hidden'} builds)`, () => {
|
[true, false].forEach(isPublic => describe(`(for ${isPublic ? 'public' : 'hidden'} builds)`, () => {
|
||||||
const authorizationHeader2 = isPublic ?
|
const authorizationHeader2 = isPublic ?
|
||||||
authorizationHeader : '--header "Authorization: FAKE_VERIFIED_NOT_TRUSTED"';
|
authorizationHeader : `--header "Authorization: ${c.BV_verify_verifiedNotTrusted}"`;
|
||||||
const cmdPrefix = curl('', `${authorizationHeader2} ${xFileHeader}`);
|
const cmdPrefix = curl('', `${authorizationHeader2} ${xFileHeader}`);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue