Files
bcc39bf21a chore(deps): update npm dev (major) (#753)
Redo of https://github.com/slsa-framework/slsa-verifier/pull/654

- Fix dev-dependencies related to es-lint that the renovate-bot couldn't
auto-fix

- a few commas automatically added by the new linter

- use node20 for tests to avoid caompatibility warnings

```
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/parser@7.5.0',
npm WARN EBADENGINE   required: { node: '^18.18.0 || >=20.0.0' },
npm WARN EBADENGINE   current: { node: 'v16.20.2', npm: '8.19.4' }
npm WARN EBADENGINE }
```

---------

Signed-off-by: Mend Renovate <bot@renovateapp.com>
Signed-off-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
Co-authored-by: Mend Renovate <bot@renovateapp.com>
2024-04-02 17:44:08 -07:00

71 lines
2.2 KiB
TypeScript

// Copyright 2022 SLSA Authors
//
// 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
//
// https://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.
const exec = require("@actions/exec");
const index = require("../lib/index");
const fs = require("fs");
describe("Test validVersion", function () {
it("Accepts v0.0.1", function () {
expect(index.validVersion("v1.0.0")).toBe(true);
});
it("Accepts v1.2.0", function () {
expect(index.validVersion("v1.0.0")).toBe(true);
});
it("Rejects foobar", function () {
expect(index.validVersion("foobar")).toBe(false);
});
it("Rejects commit hashes", function () {
expect(
index.validVersion(
"1326430d044e8a9522c51e5f721e237b5f75acb6b4e518d129f669403cf7a79a",
),
).toBe(false);
});
});
describe("Test fileHasExpectedSha256Hash", function () {
it("throws an error when the file does not exist", function () {
expect(function () {
index.fileHasExpectedSha256Hash("/path/to/nowhere", "12345");
}).toThrow();
});
describe("Tests accessing real files", function () {
beforeEach(function () {
this.tmpDir = fs.mkdtempSync("jasmine");
this.testFile = `${this.tmpDir}/testfile`;
fs.writeFileSync(this.testFile, "test data");
});
afterEach(function () {
fs.rmSync(this.tmpDir, { recursive: true });
});
it("Returns false when the computed and expected hashes don't match", function () {
expect(index.fileHasExpectedSha256Hash(this.testFile, "foobar")).toBe(
false,
);
});
it("Returns true when the computed and expected hashes don't match", function () {
expect(
index.fileHasExpectedSha256Hash(
this.testFile,
"916f0027a575074ce72a331777c3478d6513f786a591bd892da1a577bf2335f9",
),
).toBe(true);
});
});
});