Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,40 +73,73 @@ describe('configurationService', () => {
})

describe('internal-or-public URL helpers', () => {
it('should prefer internal over public URL for GitLab, Vault, Harbor, Nexus, SonarQube', () => {
service.gitlabInternalUrl = 'https://gitlab.internal'
service.vaultInternalUrl = 'https://vault.internal'
service.harborInternalUrl = 'https://harbor.internal'
service.nexusInternalUrl = 'https://nexus.internal'
service.sonarqubeInternalUrl = 'https://sonar.internal'

expect(service.getInternalOrPublicGitlabUrl()).toBe('https://gitlab.internal')
expect(service.getInternalOrPublicVaultUrl()).toBe('https://vault.internal')
expect(service.getInternalOrPublicHarborUrl()).toBe('https://harbor.internal')
expect(service.getInternalOrPublicNexusUrl()).toBe('https://nexus.internal')
expect(service.getInternalOrPublicSonarqubeUrl()).toBe('https://sonar.internal')
it('should prefer internal over public URL for GitLab, Vault, Harbor, Nexus, SonarQube', async () => {
vi.stubEnv('GITLAB_URL', 'https://gitlab.public')
vi.stubEnv('VAULT_URL', 'https://vault.public')
vi.stubEnv('HARBOR_URL', 'https://harbor.public')
vi.stubEnv('NEXUS_URL', 'https://nexus.public')
vi.stubEnv('SONARQUBE_URL', 'https://sonar.public')
vi.stubEnv('GITLAB_INTERNAL_URL', 'https://gitlab.internal')
vi.stubEnv('VAULT_INTERNAL_URL', 'https://vault.internal')
vi.stubEnv('HARBOR_INTERNAL_URL', 'https://harbor.internal')
vi.stubEnv('NEXUS_INTERNAL_URL', 'https://nexus.internal')
vi.stubEnv('SONARQUBE_INTERNAL_URL', 'https://sonar.internal')

const testService = await Test.createTestingModule({
providers: [ConfigurationService],
}).compile().then(m => m.get<ConfigurationService>(ConfigurationService))

expect(testService.getInternalOrPublicGitlabUrl()).toBe('https://gitlab.internal')
expect(testService.getInternalOrPublicVaultUrl()).toBe('https://vault.internal')
expect(testService.getInternalOrPublicHarborUrl()).toBe('https://harbor.internal')
expect(testService.getInternalOrPublicNexusUrl()).toBe('https://nexus.internal')
expect(testService.getInternalOrPublicSonarqubeUrl()).toBe('https://sonar.internal')
})

it('should fall back to public URL for GitLab, Vault, Harbor, Nexus, SonarQube when internal is unset', () => {
service.gitlabUrl = 'https://gitlab.public'
service.vaultUrl = 'https://vault.public'
service.harborUrl = 'https://harbor.public'
service.nexusUrl = 'https://nexus.public'
service.sonarqubeUrl = 'https://sonar.public'

expect(service.getInternalOrPublicGitlabUrl()).toBe('https://gitlab.public')
expect(service.getInternalOrPublicVaultUrl()).toBe('https://vault.public')
expect(service.getInternalOrPublicHarborUrl()).toBe('https://harbor.public')
expect(service.getInternalOrPublicNexusUrl()).toBe('https://nexus.public')
expect(service.getInternalOrPublicSonarqubeUrl()).toBe('https://sonar.public')
it('should fall back to public URL for GitLab, Vault, Harbor, Nexus, SonarQube when internal is unset', async () => {
vi.stubEnv('GITLAB_URL', 'https://gitlab.public')
vi.stubEnv('GITLAB_INTERNAL_URL', '')
vi.stubEnv('VAULT_URL', 'https://vault.public')
vi.stubEnv('VAULT_INTERNAL_URL', '')
vi.stubEnv('HARBOR_URL', 'https://harbor.public')
vi.stubEnv('HARBOR_INTERNAL_URL', '')
vi.stubEnv('NEXUS_URL', 'https://nexus.public')
vi.stubEnv('NEXUS_INTERNAL_URL', '')
vi.stubEnv('SONARQUBE_URL', 'https://sonar.public')
vi.stubEnv('SONARQUBE_INTERNAL_URL', '')

const testService = await Test.createTestingModule({
providers: [ConfigurationService],
}).compile().then(m => m.get<ConfigurationService>(ConfigurationService))

expect(testService.getInternalOrPublicGitlabUrl()).toBe('https://gitlab.public')
expect(testService.getInternalOrPublicVaultUrl()).toBe('https://vault.public')
expect(testService.getInternalOrPublicHarborUrl()).toBe('https://harbor.public')
expect(testService.getInternalOrPublicNexusUrl()).toBe('https://nexus.public')
expect(testService.getInternalOrPublicSonarqubeUrl()).toBe('https://sonar.public')
})

it('should return undefined for internal-or-public URL when neither side is configured', () => {
expect(service.getInternalOrPublicGitlabUrl()).toBeUndefined()
expect(service.getInternalOrPublicVaultUrl()).toBeUndefined()
expect(service.getInternalOrPublicHarborUrl()).toBeUndefined()
expect(service.getInternalOrPublicNexusUrl()).toBeUndefined()
expect(service.getInternalOrPublicSonarqubeUrl()).toBeUndefined()
it('should return undefined for internal-or-public URL when neither side is configured', async () => {
vi.stubEnv('GITLAB_URL', '')
vi.stubEnv('GITLAB_INTERNAL_URL', '')
vi.stubEnv('VAULT_URL', '')
vi.stubEnv('VAULT_INTERNAL_URL', '')
vi.stubEnv('HARBOR_URL', '')
vi.stubEnv('HARBOR_INTERNAL_URL', '')
vi.stubEnv('NEXUS_URL', '')
vi.stubEnv('NEXUS_INTERNAL_URL', '')
vi.stubEnv('SONARQUBE_URL', '')
vi.stubEnv('SONARQUBE_INTERNAL_URL', '')

const testService = await Test.createTestingModule({
providers: [ConfigurationService],
}).compile().then(m => m.get<ConfigurationService>(ConfigurationService))

expect(testService.getInternalOrPublicGitlabUrl()).toBeUndefined()
expect(testService.getInternalOrPublicVaultUrl()).toBeUndefined()
expect(testService.getInternalOrPublicHarborUrl()).toBeUndefined()
expect(testService.getInternalOrPublicNexusUrl()).toBeUndefined()
expect(testService.getInternalOrPublicSonarqubeUrl()).toBeUndefined()
})
})

Expand Down Expand Up @@ -173,6 +206,8 @@ describe('configurationService', () => {
})

it('should disable TLS verification for Open CDS only when explicitly set to false', async () => {
vi.stubEnv('OPENCDS_API_TLS_REJECT_UNAUTHORIZED', '')

const defaultService = await Test.createTestingModule({
providers: [ConfigurationService],
}).compile().then(m => m.get<ConfigurationService>(ConfigurationService))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,32 +128,36 @@ export class ConfigurationService {
}

getInternalOrPublicGitlabUrl() {
const url = this.gitlabInternalUrl ?? this.gitlabUrl
this.logger.log(`GitLab URL resolved: ${url} (${this.gitlabInternalUrl ? 'internal' : 'public'})`)
return url
return this.getInternalOrPublicUrl("GitLab", this.gitlabUrl, this.gitlabInternalUrl)
}

getInternalOrPublicVaultUrl() {
const url = this.vaultInternalUrl ?? this.vaultUrl
this.logger.log(`Vault URL resolved: ${url} (${this.vaultInternalUrl ? 'internal' : 'public'})`)
return url
return this.getInternalOrPublicUrl("Vault", this.vaultUrl, this.vaultInternalUrl)
}

getInternalOrPublicHarborUrl() {
const url = this.harborInternalUrl ?? this.harborUrl
this.logger.log(`Harbor URL resolved: ${url} (${this.harborInternalUrl ? 'internal' : 'public'})`)
return url
return this.getInternalOrPublicUrl("Harbor", this.harborUrl, this.harborInternalUrl)
}

getInternalOrPublicNexusUrl() {
const url = this.nexusInternalUrl ?? this.nexusUrl
this.logger.log(`Nexus URL resolved: ${url} (${this.nexusInternalUrl ? 'internal' : 'public'})`)
return url
return this.getInternalOrPublicUrl("Nexus", this.nexusUrl, this.nexusInternalUrl)
}

getInternalOrPublicSonarqubeUrl() {
const url = this.sonarqubeInternalUrl ?? this.sonarqubeUrl
this.logger.log(`SonarQube URL resolved: ${url} (${this.sonarqubeInternalUrl ? 'internal' : 'public'})`)
return this.getInternalOrPublicUrl("SonarQube", this.sonarqubeUrl, this.sonarqubeInternalUrl)
}

getInternalOrPublicUrl(name: string, publicUrl: string | undefined, internalUrl: string | undefined): string | undefined {
const trimedInternalUrl = internalUrl?.trim()
const trimmedPublicUrl = publicUrl?.trim()
const url = trimedInternalUrl || trimmedPublicUrl || undefined
let label = 'none'
if (trimedInternalUrl) {
label = 'internal'
} else if (trimmedPublicUrl) {
label = 'public'
}
this.logger.log(`${name} URL resolved: ${url ?? 'none'} (${label})`)
return url
}

Expand Down