-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow scoped client certificates (#15)
* feat: allow scoped client certificates * style: remove new line and use template literal * fix: use `node-fetch` latest cjs version * test: fix self-signed certificate regex * style: remove unused `@ts-expect-error` * fix: use Powershell in windows CI (#16) * fix: use Powershell in windows CI * revert: change step names * fix: set OS PATH in different steps * fix: set Windows PATH * fix: use Powershell v5.1 * fix: specify bvm path manually * fix: dont modify windows PATH * fix: set BVM path in PATH * fix: set user profile automatically * refactor: replace `uriToHost ` with `nerf-dart` * test: add tests * style: update * style: update * style: update * style: update * style: update * fix: conditional if https Co-authored-by: Zoltan Kochan <[email protected]> * refactor: destructure client certificates Co-authored-by: Zoltan Kochan <[email protected]> * fix: type errors * test: add more tests * feat: add url component for URL specific functions * fix: trailing slash * fix: get each uri part correctly * refactor: move `getXFromUri` to `url` component * fix: disable v8 cache * revert: disable v8 cache * refactor: make `getMaxParts` an internal function * fix: install bvm manually and use system node version * revert: install bvm globally * ci: use bit v1.6.44 * fix: install Bit v1.6.44 * chore: remove `settings.json` * refactor: change component name to `pnpm.network/config` * fix: replate `\r\n` with `\n` to match UNIX style * refactor: remove unused functions --------- Co-authored-by: Zoltan Kochan <[email protected]>
- Loading branch information
1 parent
c594fa9
commit 63b35e5
Showing
12 changed files
with
322 additions
and
35 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
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,10 @@ | ||
--- | ||
labels: ['Config', 'module'] | ||
description: 'A Config module.' | ||
--- | ||
|
||
A config module. | ||
|
||
```ts | ||
config(); | ||
``` |
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 @@ | ||
import { pickSettingByUrl } from './config'; | ||
|
||
describe('pickSettingByUrl', () => { | ||
test('should return undefined if generic object is undefined', () => { | ||
expect(pickSettingByUrl(undefined, 'https://example.com')).toBeUndefined(); | ||
}); | ||
|
||
test('should return the exact match from the generic object', () => { | ||
const settings = { 'https://example.com/': 'ExampleSetting' }; | ||
expect(pickSettingByUrl(settings, 'https://example.com')).toBe( | ||
'ExampleSetting' | ||
); | ||
}); | ||
|
||
test('should return a match using nerf dart', () => { | ||
const settings = { '//example.com/': 'NerfDartSetting' }; | ||
expect( | ||
pickSettingByUrl(settings, 'https://example.com/path/to/resource') | ||
).toBe('NerfDartSetting'); | ||
}); | ||
|
||
test('should return a match using withoutPort', () => { | ||
const settings = { | ||
'https://example.com/path/to/resource/': 'WithoutPortSetting', | ||
}; | ||
expect( | ||
pickSettingByUrl(settings, 'https://example.com:8080/path/to/resource') | ||
).toBe('WithoutPortSetting'); | ||
}); | ||
|
||
test('should return undefined if no match is found', () => { | ||
const settings = { 'https://example.com/': 'ExampleSetting' }; | ||
expect(pickSettingByUrl(settings, 'https://nomatch.com')).toBeUndefined(); | ||
}); | ||
|
||
test('should recursively match using withoutPort', () => { | ||
const settings = { 'https://example.com/': 'RecursiveSetting' }; | ||
expect(pickSettingByUrl(settings, 'https://example.com:8080')).toBe( | ||
'RecursiveSetting' | ||
); | ||
}); | ||
}); |
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,40 @@ | ||
import nerfDart from 'nerf-dart'; | ||
|
||
function getMaxParts(uris: string[]) { | ||
return uris.reduce((max, uri) => { | ||
const parts = uri.split('/').length; | ||
return parts > max ? parts : max; | ||
}, 0); | ||
} | ||
|
||
export function pickSettingByUrl<T>( | ||
generic: { [key: string]: T } | undefined, | ||
uri: string | ||
): T | undefined { | ||
if (!generic) return undefined; | ||
if (generic[uri]) return generic[uri]; | ||
/* const { nerf, withoutPort } = parseUri(uri); */ | ||
const nerf = nerfDart(uri); | ||
const withoutPort = removePort(new URL(uri)); | ||
if (generic[nerf]) return generic[nerf]; | ||
if (generic[withoutPort]) return generic[withoutPort]; | ||
const maxParts = getMaxParts(Object.keys(generic)); | ||
const parts = nerf.split('/'); | ||
for (let i = Math.min(parts.length, maxParts) - 1; i >= 3; i--) { | ||
const key = `${parts.slice(0, i).join('/')}/`; | ||
if (generic[key]) { | ||
return generic[key]; | ||
} | ||
} | ||
if (withoutPort !== uri) { | ||
return pickSettingByUrl(generic, withoutPort); | ||
} | ||
return undefined; | ||
} | ||
|
||
function removePort(config: URL): string { | ||
if (config.port === '') return config.href; | ||
config.port = ''; | ||
const res = config.toString(); | ||
return res.endsWith('/') ? res : `${res}/`; | ||
} |
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 @@ | ||
export { pickSettingByUrl } from './config'; |
Oops, something went wrong.