-
Notifications
You must be signed in to change notification settings - Fork 6
fix(server-nestjs/sonarqube): harden sonarqube reconciliation with strict key matching and idempotent init #2299
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
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
|
StephaneTrebel marked this conversation as resolved.
|
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,33 @@ | ||
| import { generateProjectKey as legacyGenerateProjectKey } from '@cpn-console/hooks' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { generateProjectKey } from './crypto' | ||
|
|
||
| describe('generateProjectKey', () => { | ||
| it('matches the legacy @cpn-console/hooks implementation byte-for-byte', () => { | ||
| const cases: [string, string][] = [ | ||
| ['my-app', 'my-repo'], | ||
| ['my-app', 'front'], | ||
| ['my-app-2', 'front'], | ||
| ['slug-with-many-dashes', 'repo-with-dashes'], | ||
| ['a', 'b'], | ||
| ] | ||
| for (const [slug, repo] of cases) { | ||
| expect(generateProjectKey(slug, repo)).toBe(legacyGenerateProjectKey(slug, repo)) | ||
| } | ||
| }) | ||
|
|
||
| it('produces stable known keys', () => { | ||
| // Golden values: existing SonarQube projects were created with these exact keys, | ||
| // and reconciliation recomputes them to decide ownership. Any change here means | ||
| // the console would stop recognizing (and could delete) existing projects. | ||
| expect(generateProjectKey('my-app', 'my-repo')).toBe('my-app-my-repo-923f') | ||
| expect(generateProjectKey('my-app', 'front')).toBe('my-app-front-1013') | ||
| expect(generateProjectKey('my-app', 'api')).toBe('my-app-api-a814') | ||
| }) | ||
|
|
||
| it('disambiguates identical slug-repo concatenations via the hash suffix', () => { | ||
| // "my-app" + "front-api" and "my-app-front" + "api" share the prefix | ||
| // "my-app-front-api-"; only the repo hash tells them apart. | ||
| expect(generateProjectKey('my-app', 'front-api')).not.toBe(generateProjectKey('my-app-front', 'api')) | ||
| }) | ||
| }) |
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,18 @@ | ||
| import crypto, { createHmac } from 'node:crypto' | ||
|
|
||
| export function generateRandomPassword(length = 24) { | ||
| const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@-_#*' | ||
| return Array.from(crypto.getRandomValues(new Uint32Array(length)), x => chars[x % chars.length]) | ||
| .join('') | ||
| } | ||
|
|
||
| // Must stay byte-for-byte identical to the legacy @cpn-console/hooks implementation: | ||
| // existing SonarQube project keys were generated with it, and ownership matching | ||
| // recomputes keys to decide which projects to reconcile or delete. | ||
| export function generateProjectKey(projectSlug: string, internalRepoName: string) { | ||
|
KepoParis marked this conversation as resolved.
|
||
| const repoHash = createHmac('sha256', '') | ||
| .update(internalRepoName) | ||
| .digest('hex') | ||
| .slice(0, 4) | ||
| return `${projectSlug}-${internalRepoName}-${repoHash}` | ||
| } | ||
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.