-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate referencing and configuration of registries
- Loading branch information
1 parent
7d077fd
commit 6314e14
Showing
19 changed files
with
322 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: 'docker' # See documentation for possible values | ||
directory: '/' # Location of package manifests | ||
schedule: | ||
interval: 'weekly' | ||
time: '03:00' | ||
day: 'sunday' | ||
open-pull-requests-limit: 10 | ||
- package-ecosystem: 'npm' # See documentation for possible values | ||
directory: '/client' # Location of package manifests | ||
schedule: | ||
interval: 'daily' | ||
time: '03:15' | ||
open-pull-requests-limit: 10 | ||
registries: | ||
- reg1 | ||
- reg2 | ||
insecure-external-code-execution: 'deny' | ||
ignore: | ||
- dependency-name: 'react' | ||
update-types: ['version-update:semver-major'] | ||
- dependency-name: 'react-dom' | ||
update-types: ['version-update:semver-major'] | ||
- dependency-name: '@types/react' | ||
update-types: ['version-update:semver-major'] | ||
- dependency-name: '@types/react-dom' | ||
update-types: ['version-update:semver-major'] | ||
registries: | ||
reg1: | ||
type: nuget-feed | ||
url: 'https://pkgs.dev.azure.com/dependabot/_packaging/dependabot/nuget/v3/index.json' | ||
token: ':${{DEFAULT_TOKEN}}' | ||
reg2: | ||
type: npm-registry | ||
url: 'https://pkgs.dev.azure.com/dependabot/_packaging/dependabot-npm/npm/registry/' | ||
token: 'tingle-npm:${{DEFAULT_TOKEN}}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,39 @@ | ||
import { load } from "js-yaml"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import { parseRegistries } from "../../task/utils/parseConfigFile"; | ||
import { parseRegistries, parseUpdates, validateConfiguration } from "../../task/utils/parseConfigFile"; | ||
import { IDependabotRegistry, IDependabotUpdate } from "../../task/IDependabotConfig"; | ||
|
||
describe("Parse configuration file", () => { | ||
it("Parsing works as expected", () => { | ||
let config: any = load(fs.readFileSync('tests/utils/dependabot.yml', "utf-8")); | ||
let updates = parseUpdates(config); | ||
expect(updates.length).toBe(2); | ||
|
||
// first | ||
const first = updates[0]; | ||
expect(first.directory).toBe('/'); | ||
expect(first.packageEcosystem).toBe('docker'); | ||
expect(first.insecureExternalCodeExecution).toBe(undefined); | ||
expect(first.registries).toEqual([]); | ||
|
||
// second | ||
const second = updates[1]; | ||
expect(second.directory).toBe('/client'); | ||
expect(second.packageEcosystem).toBe('npm'); | ||
expect(second.insecureExternalCodeExecution).toBe('deny'); | ||
expect(second.registries).toEqual(['reg1', 'reg2']); | ||
}); | ||
}); | ||
|
||
describe("Parse registries", () => { | ||
it("Parsing works as expected", () => { | ||
let config: any = load(fs.readFileSync('tests/utils/sample-registries.yml', "utf-8")); | ||
let registries = parseRegistries(config); | ||
expect(registries.length).toBe(11); | ||
expect(Object.keys(registries).length).toBe(11); | ||
|
||
// composer-repository | ||
var registry = registries[0]; | ||
var registry = registries['composer']; | ||
expect(registry.type).toBe('composer_repository'); | ||
expect(registry.url).toBe('https://repo.packagist.com/example-company/'); | ||
expect(registry["index-url"]).toBe(undefined); | ||
|
@@ -27,7 +50,7 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(undefined); | ||
|
||
// docker-registry | ||
registry = registries[1]; | ||
registry = registries['dockerhub']; | ||
expect(registry.type).toBe('docker_registry'); | ||
expect(registry.url).toBe(undefined); | ||
expect(registry["index-url"]).toBe(undefined); | ||
|
@@ -44,7 +67,7 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(true); | ||
|
||
// git | ||
registry = registries[2]; | ||
registry = registries['github-octocat']; | ||
expect(registry.type).toBe('git'); | ||
expect(registry.url).toBe('https://github.com'); | ||
expect(registry["index-url"]).toBe(undefined); | ||
|
@@ -61,7 +84,7 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(undefined); | ||
|
||
// hex-organization | ||
registry = registries[3]; | ||
registry = registries['github-hex-org']; | ||
expect(registry.type).toBe('hex_organization'); | ||
expect(registry.url).toBe(undefined); | ||
expect(registry["index-url"]).toBe(undefined); | ||
|
@@ -78,7 +101,7 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(undefined); | ||
|
||
// hex-repository | ||
registry = registries[4]; | ||
registry = registries['github-hex-repository']; | ||
expect(registry.type).toBe('hex_repository'); | ||
expect(registry.url).toBe('https://private-repo.example.com'); | ||
expect(registry.registry).toBe(undefined); | ||
|
@@ -94,7 +117,7 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(undefined); | ||
|
||
// maven-repository | ||
registry = registries[5]; | ||
registry = registries['maven-artifactory']; | ||
expect(registry.type).toBe('maven_repository'); | ||
expect(registry.url).toBe('https://artifactory.example.com'); | ||
expect(registry["index-url"]).toBe(undefined); | ||
|
@@ -111,7 +134,7 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(true); | ||
|
||
// npm-registry | ||
registry = registries[6]; | ||
registry = registries['npm-github']; | ||
expect(registry.type).toBe('npm_registry'); | ||
expect(registry.url).toBe(undefined); | ||
expect(registry["index-url"]).toBe(undefined); | ||
|
@@ -128,7 +151,7 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(true); | ||
|
||
// nuget-feed | ||
registry = registries[7]; | ||
registry = registries['nuget-azure-devops']; | ||
expect(registry.type).toBe('nuget_feed'); | ||
expect(registry.url).toBe('https://pkgs.dev.azure.com/contoso/_packaging/My_Feed/nuget/v3/index.json'); | ||
expect(registry["index-url"]).toBe(undefined); | ||
|
@@ -145,7 +168,7 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(undefined); | ||
|
||
// python-index | ||
registry = registries[8]; | ||
registry = registries['python-azure']; | ||
expect(registry.type).toBe('python_index'); | ||
expect(registry.url).toBe(undefined); | ||
expect(registry["index-url"]).toBe('https://pkgs.dev.azure.com/octocat/_packaging/my-feed/pypi/example'); | ||
|
@@ -162,7 +185,7 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(true); | ||
|
||
// rubygems-server | ||
registry = registries[9]; | ||
registry = registries['ruby-github']; | ||
expect(registry.type).toBe('rubygems_server'); | ||
expect(registry.url).toBe('https://rubygems.pkg.github.com/octocat/github_api'); | ||
expect(registry["index-url"]).toBe(undefined); | ||
|
@@ -179,7 +202,7 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(false); | ||
|
||
// terraform-registry | ||
registry = registries[10]; | ||
registry = registries['terraform-example']; | ||
expect(registry.type).toBe('terraform_registry'); | ||
expect(registry.url).toBe(undefined); | ||
expect(registry["index-url"]).toBe(undefined); | ||
|
@@ -196,3 +219,45 @@ describe("Parse registries", () => { | |
expect(registry["replaces-base"]).toBe(undefined); | ||
}); | ||
}); | ||
|
||
describe("Validate registries", () => { | ||
it("Validation works as expected", () => { | ||
// let config: any = load(fs.readFileSync('tests/utils/dependabot.yml', "utf-8")); | ||
// let updates = parseUpdates(config); | ||
// expect(updates.length).toBe(2); | ||
|
||
var updates: IDependabotUpdate[] = [ | ||
{ | ||
packageEcosystem: "npm", | ||
directory: "/", | ||
registries: ["dummy1", "dummy2"], | ||
}, | ||
]; | ||
|
||
var registries: Record<string, IDependabotRegistry> = { | ||
'dummy1': { | ||
type: 'nuget', | ||
url: "https://pkgs.dev.azure.com/contoso/_packaging/My_Feed/nuget/v3/index.json", | ||
token: "pwd_1234567890", | ||
}, | ||
'dummy2': { | ||
type: "python-index", | ||
url: "https://pkgs.dev.azure.com/octocat/_packaging/my-feed/pypi/example", | ||
username: "[email protected]", | ||
password: "pwd_1234567890", | ||
"replaces-base": true, | ||
}, | ||
}; | ||
|
||
// works as expected | ||
validateConfiguration(updates, registries); | ||
|
||
// fails: registry not referenced | ||
updates[0].registries = []; | ||
expect(() => validateConfiguration(updates, registries)).toThrow(`Registries: 'dummy1,dummy2' have not been referenced by any update`); | ||
|
||
// fails: registrynot configured | ||
updates[0].registries = ["dummy1", "dummy2", "dummy3",]; | ||
expect(() => validateConfiguration(updates, registries)).toThrow(`Referenced registries: 'dummy3' have not been configured in the root of dependabot.yml`); | ||
}); | ||
}); |
Oops, something went wrong.