auditjs
Version:
Audit dependencies to identify known vulnerabilities and maintenance problems
65 lines • 3.69 kB
JavaScript
;
/*
* Copyright 2019-Present Sonatype Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const OssIndexRequestService_1 = require("./OssIndexRequestService");
const TestHelper_1 = __importDefault(require("../Tests/TestHelper"));
const Coordinates_1 = require("../Types/Coordinates");
const nock_1 = __importDefault(require("nock"));
const rimraf_1 = __importDefault(require("rimraf"));
// This will only work on Linux/OS X, find a better Windows friendly path
const CACHE_LOCATION = '/tmp/.ossindex';
const OSS_INDEX_BASE_URL = 'http://ossindex.sonatype.org/';
describe('OssIndexRequestService', () => {
it('should have its request rejected when the OSS Index server is down', () => __awaiter(void 0, void 0, void 0, function* () {
rimraf_1.default.sync(CACHE_LOCATION);
(0, nock_1.default)(OSS_INDEX_BASE_URL)
.post('/api/v3/component-report')
.replyWithError('you messed up!');
const requestService = new OssIndexRequestService_1.OssIndexRequestService(undefined, undefined, CACHE_LOCATION, OSS_INDEX_BASE_URL);
const coords = [new Coordinates_1.Coordinates('commander', '2.12.2', '@types')];
return (0, TestHelper_1.default)(requestService.callOSSIndexOrGetFromCache(coords)).to.eventually.be.rejected;
}));
it('should return a valid response when given a valid component request', () => __awaiter(void 0, void 0, void 0, function* () {
rimraf_1.default.sync(CACHE_LOCATION);
const expectedOutput = [
{
coordinates: 'pkg:npm/%40types/commander@2.12.2',
reference: 'https://ossindex.sonatype.org/blahblahblah',
vulnerabilities: [],
},
];
(0, nock_1.default)(OSS_INDEX_BASE_URL)
.post('/api/v3/component-report')
.reply(200, expectedOutput);
const requestService = new OssIndexRequestService_1.OssIndexRequestService(undefined, undefined, CACHE_LOCATION, OSS_INDEX_BASE_URL);
const coords = [new Coordinates_1.Coordinates('commander', '2.12.2', '@types')];
return (0, TestHelper_1.default)(requestService.callOSSIndexOrGetFromCache(coords)).to.eventually.deep.equal(expectedOutput);
}));
});
//# sourceMappingURL=OssIndexRequestService.spec.js.map