-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add credential-free fixture dev server #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| import "dotenv/config"; | ||
|
|
||
| import { loadServerConfig } from "./config/env.js"; | ||
| import { createFixtureApp } from "./dev/fixture-app.js"; | ||
|
|
||
| const config = loadServerConfig(); | ||
| const app = createFixtureApp(config.cacheTtlMs); | ||
|
|
||
| app.listen(config.port, () => { | ||
| console.log(`policychecks fixture server listening on http://localhost:${config.port}`); | ||
| console.log("GitHub API calls and webhook handling are disabled in fixture mode."); | ||
| }); |
This file contains hidden or 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,86 @@ | ||
| import { InMemoryBadgeCache } from "../cache/cache.js"; | ||
| import type { GitHubClient } from "../github/client.js"; | ||
| import type { InstallationResolution } from "../github/installations.js"; | ||
| import { BadgeService, type InstallationResolver } from "../server/badge-service.js"; | ||
| import { createHttpApp } from "../server/http-app.js"; | ||
|
|
||
| const fixtureGitHub: GitHubClient = { | ||
| async getRepository() { | ||
| return { | ||
| id: 1, | ||
| default_branch: "main", | ||
| web_commit_signoff_required: true, | ||
| security_and_analysis: { | ||
| secret_scanning: { status: "enabled" }, | ||
| secret_scanning_push_protection: { status: "disabled" } | ||
| } | ||
| }; | ||
| }, | ||
| async getImmutableReleases() { | ||
| return { | ||
| enabled: true, | ||
| enforced_by_owner: false | ||
| }; | ||
| }, | ||
| async getActionsPermissions() { | ||
| return { | ||
| sha_pinning_required: true | ||
| }; | ||
| }, | ||
| async getBranchRules() { | ||
| return [ | ||
| { type: "deletion" }, | ||
| { type: "non_fast_forward" }, | ||
| { type: "pull_request", parameters: { required_approving_review_count: 1 } }, | ||
| { type: "required_linear_history" }, | ||
| { type: "required_signatures" }, | ||
| { | ||
| type: "required_status_checks", | ||
| parameters: { required_status_checks: [{ context: "test" }] } | ||
| } | ||
| ]; | ||
| }, | ||
| async getCommunityProfile() { | ||
| return { | ||
| health_percentage: 75, | ||
| files: { | ||
| code_of_conduct: { name: "Contributor Covenant", key: "contributor_covenant" }, | ||
| contributing: {}, | ||
| license: { name: "MIT License", key: "mit", spdx_id: "MIT" }, | ||
| readme: {} | ||
| }, | ||
| content_reports_enabled: false, | ||
| updated_at: null | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| const fixtureResolver: InstallationResolver = { | ||
| async resolve(owner: string, repo: string): Promise<InstallationResolution> { | ||
| const now = new Date().toISOString(); | ||
|
|
||
| return { | ||
| status: "ok", | ||
| github: fixtureGitHub, | ||
| repository: { | ||
| owner, | ||
| repo, | ||
| repositoryId: 1, | ||
| installationId: 1, | ||
| defaultBranch: "main", | ||
| createdAt: now, | ||
| updatedAt: now | ||
| } | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| export function createFixtureApp(cacheTtlMs: number) { | ||
| const badgeService = new BadgeService({ | ||
| cache: new InMemoryBadgeCache(), | ||
| installationResolver: fixtureResolver, | ||
| cacheTtlMs | ||
| }); | ||
|
|
||
| return createHttpApp(badgeService); | ||
| } |
This file contains hidden or 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 hidden or 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,43 @@ | ||
| import request from "supertest"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { createFixtureApp } from "../../src/dev/fixture-app.js"; | ||
|
|
||
| describe("fixture development app", () => { | ||
| const app = createFixtureApp(3_600_000); | ||
|
|
||
| it("starts without GitHub credentials", async () => { | ||
| await request(app).get("/healthz").expect(200).expect({ ok: true }); | ||
| }); | ||
|
|
||
| it("evaluates badges through deterministic GitHub fixtures", async () => { | ||
| const response = await request(app).get("/github/example/project/info.json").expect(200); | ||
|
|
||
| expect(response.body.badges).toHaveLength(12); | ||
| expect(response.body.badges).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ badgeId: "immutable-releases", result: "enabled" }), | ||
| expect.objectContaining({ badgeId: "secret-push-protection-enabled", result: "disabled" }), | ||
| expect.objectContaining({ badgeId: "community-health", result: "75/100" }) | ||
| ]) | ||
| ); | ||
| }); | ||
|
|
||
| it("renders fixture badge SVGs", async () => { | ||
| const response = await request(app) | ||
| .get("/github/example/project/sha-pinning-required.svg") | ||
| .expect(200) | ||
| .expect("Content-Type", /image\/svg\+xml/); | ||
|
|
||
| const svg = response.text ?? response.body.toString("utf8"); | ||
| expect(svg).toContain("SHA pinning"); | ||
| expect(svg).toContain("enabled"); | ||
| }); | ||
|
|
||
| it("does not expose the authenticated webhook route", async () => { | ||
| await request(app) | ||
| .post("/github/webhook") | ||
| .send({ zen: "Keep it logically awesome." }) | ||
| .expect(404); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.