Skip to content
Snippets Groups Projects
Commit 1e2a3382 authored by BITARD Michaël's avatar BITARD Michaël Committed by MAUBERT Vincent
Browse files

fix(proxy): extrait le host sans le port (!1519)

parent 48fcf722
No related branches found
No related tags found
1 merge request!1519fix(proxy): extrait le host sans le port
Pipeline #419676 failed
......@@ -4,24 +4,14 @@ import { caminoAnneeValidator, getCurrentAnnee } from 'camino-common/src/date'
import { caminoConfigValidator } from 'camino-common/src/static/config'
import { isNullOrUndefined } from 'camino-common/src/typescript-tools'
import { z } from 'zod'
import { urlToSplit } from 'camino-common/src/strings'
if (process.env.VITEST !== 'true') {
dotenv.config({ path: resolve(process.cwd(), '../../.env') })
}
const JWT_ALGORITHMS = ['HS256', 'HS384', 'HS512', 'RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES512', 'PS256', 'PS384', 'PS512', 'none'] as const
const urlToSplit = (url: undefined | string): { value: string; host: string; port: number } | undefined => {
if (isNullOrUndefined(url)) {
return url
}
const value = new URL(url)
return {
value: url,
host: value.host,
port: parseInt(value.port),
}
}
const httpsProxyValidator = z.string().url().optional().transform(urlToSplit)
const configValidator = caminoConfigValidator.extend({
......
import { test, expect } from 'vitest'
import { capitalize, levenshtein, slugify } from './strings'
import { capitalize, levenshtein, slugify, urlToSplit } from './strings'
test('urlToSplit', () => {
expect(urlToSplit('http://proxy-paas.dgaln-pre1.eco4.sihc.fr:3128')).toStrictEqual({
value: 'http://proxy-paas.dgaln-pre1.eco4.sihc.fr:3128',
host: 'proxy-paas.dgaln-pre1.eco4.sihc.fr',
port: 3128,
})
expect(urlToSplit(undefined)).toStrictEqual(undefined)
expect(urlToSplit('http://google.fr')).toStrictEqual({ value: 'http://google.fr', host: 'google.fr', port: 80 })
expect(urlToSplit('https://google.fr')).toStrictEqual({ value: 'https://google.fr', host: 'google.fr', port: 443 })
})
test('capitalize', () => {
expect(capitalize('')).toBe('')
......
import { isNullOrUndefined } from './typescript-tools'
export const capitalize = <T extends string>(text: T): Capitalize<T> => {
if (text.length > 0) {
return (text.substring(0, 1).toUpperCase() + text.substring(1)) as Capitalize<T>
......@@ -6,6 +8,25 @@ export const capitalize = <T extends string>(text: T): Capitalize<T> => {
return text as Capitalize<T>
}
export const urlToSplit = (url: undefined | string): { value: string; host: string; port: number } | undefined => {
if (isNullOrUndefined(url)) {
return url
}
const value = new URL(url)
let port = parseInt(value.port)
if (isNaN(port)) {
port = url.startsWith('https://') ? 443 : 80
}
return {
value: url,
host: value.hostname,
port: port,
}
}
export const levenshtein = (s: string, t: string): number => {
if (s === t) {
return 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment