forked from kugaevsky/outline-server-arm64
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ben Schwartz
committed
May 13, 2022
1 parent
41ae0f6
commit 263974e
Showing
19 changed files
with
175 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
; Enforces that the user is `npm install`ing with the correct node version. | ||
engine-strict=true | ||
|
||
; Workaround for conflict between the default location(s) of node-forge and the | ||
; location expected by Typescript, Jasmine, and Electron. | ||
prefer-dedupe=true |
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
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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,67 @@ | ||
// Copyright 2022 The Outline Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import {PathApiClient} from './path_api'; | ||
|
||
describe('PathApi', () => { | ||
// Mock fetcher | ||
let lastRequest: HttpRequest; | ||
let nextResponse: Promise<HttpResponse>; | ||
|
||
const fetcher = (request: HttpRequest) => { | ||
lastRequest = request; | ||
return nextResponse; | ||
}; | ||
|
||
beforeEach(() => { | ||
lastRequest = undefined; | ||
nextResponse = undefined; | ||
}); | ||
|
||
const api = new PathApiClient('https://asdf.test/foo', fetcher); | ||
|
||
it('GET', async () => { | ||
const response = {status: 200, body: '{"asdf": true}'}; | ||
nextResponse = Promise.resolve(response); | ||
expect(await api.request('bar')).toEqual({asdf: true}); | ||
expect(lastRequest).toEqual({ | ||
url: 'https://asdf.test/foo/bar', | ||
method: 'GET', | ||
}); | ||
}); | ||
|
||
it('PUT form data', async () => { | ||
const response = {status: 200, body: '{"asdf": true}'}; | ||
nextResponse = Promise.resolve(response); | ||
expect(await api.requestForm('bar', 'PUT', {name: 'value'})).toEqual({asdf: true}); | ||
expect(lastRequest).toEqual({ | ||
url: 'https://asdf.test/foo/bar', | ||
method: 'PUT', | ||
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, | ||
body: 'name=value', | ||
}); | ||
}); | ||
|
||
it('POST JSON data', async () => { | ||
const response = {status: 200, body: '{"asdf": true}'}; | ||
nextResponse = Promise.resolve(response); | ||
expect(await api.requestJson('bar', 'POST', {key: 'value'})).toEqual({asdf: true}); | ||
expect(lastRequest).toEqual({ | ||
url: 'https://asdf.test/foo/bar', | ||
method: 'POST', | ||
headers: {'Content-Type': 'application/json'}, | ||
body: '{"key":"value"}', | ||
}); | ||
}); | ||
}); |
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,28 @@ | ||
// Copyright 2022 The Outline Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import {makePathApiClient} from './fetcher'; | ||
|
||
describe('makePathApiClient', () => { | ||
const api = makePathApiClient('https://api.github.com/repos/Jigsaw-Code/'); | ||
|
||
if (process?.versions?.node) { | ||
// This test relies on fetch(), which doesn't exist in Node (yet). | ||
return; | ||
} | ||
it('GET', async () => { | ||
const response = await api.request<{name: string}>('outline-server'); | ||
expect(response.name).toEqual('outline-server'); | ||
}); | ||
}); |
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,43 @@ | ||
// Copyright 2022 The Outline Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import {Fetcher, PathApiClient} from '../infrastructure/path_api'; | ||
|
||
async function fetchWrapper(request: HttpRequest): Promise<HttpResponse> { | ||
const response = await fetch(request.url, request); | ||
return { | ||
status: response.status, | ||
body: await response.text(), | ||
}; | ||
} | ||
|
||
/** | ||
* @param fingerprint A SHA-256 hash of the expected leaf certificate, in binary encoding. | ||
* @returns An HTTP client that enforces `fingerprint`, if set. | ||
*/ | ||
function makeFetcher(fingerprint?: string): Fetcher { | ||
if (fingerprint) { | ||
return (request) => fetchWithPin(request, fingerprint); | ||
} | ||
return fetchWrapper; | ||
} | ||
|
||
/** | ||
* @param base A valid URL | ||
* @param fingerprint A SHA-256 hash of the expected leaf certificate, in binary encoding. | ||
* @returns A fully initialized API client. | ||
*/ | ||
export function makePathApiClient(base: string, fingerprint?: string): PathApiClient { | ||
return new PathApiClient(base, makeFetcher(fingerprint)); | ||
} |
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
Oops, something went wrong.