Files
firefox-accounts-mirror/packages/browserid-verifier/tests/service-failure.js
Ben Bangert ecb1a7f5ea fix: tweaks for test all to pass
Because:

* Test all didn't run in parallel to take advantage of more cores and
  a few older tests were flakey.
* Tests would hang as packages had a default test that was in watch
  mode.

This commit:

* Updates several flakey tests and runs the test all in parallel for a
  shorter completion time.
* Updates settings and payment-server packages to have new watch command
  and deafult test command that runs the tests.

Closes #FXA-6096
2022-10-18 15:26:45 -07:00

81 lines
2.2 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* global describe,it,before,after */
var IdP = require('browserid-local-verify/testing').IdP,
Client = require('browserid-local-verify/testing').Client,
Verifier = require('./lib/verifier.js'),
should = require('should'),
shouldReturnSecurityHeaders = require('./lib/should-return-security-headers.js'),
request = require('request');
describe('audience tests', function () {
var verifier = new Verifier({ testServiceFailure: true });
var idp = new IdP();
var client;
before(async () => {
await new Promise((resolve) => idp.start(resolve));
await new Promise((resolve) => verifier.start(resolve));
client = new Client({ idp: idp });
});
after(async () => {
await new Promise((resolve) => verifier.stop(resolve));
await new Promise((resolve) => idp.stop(resolve));
});
var assertion;
it('test assertion should be created', function (done) {
client.assertion({ audience: 'http://example.com' }, function (err, ass) {
assertion = ass;
done(err);
});
});
it('(v1 api) should return a 503 on service failure', function (done) {
request(
{
method: 'post',
url: verifier.v1url(),
json: true,
body: {
assertion: assertion,
audience: 'http://example.com',
},
},
function (err, r) {
should.not.exist(err);
(503).should.equal(r.statusCode);
'failure'.should.equal(r.body.status);
shouldReturnSecurityHeaders(r);
done();
}
);
});
it('(v2 api) should return a 503 on service failure', function (done) {
request(
{
method: 'post',
url: verifier.url(),
json: true,
body: {
assertion: assertion,
audience: 'http://example.com',
},
},
function (err, r) {
should.not.exist(err);
(503).should.equal(r.statusCode);
'failure'.should.equal(r.body.status);
shouldReturnSecurityHeaders(r);
done();
}
);
});
});