-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
d3f6e7e
commit 3ed89f3
Showing
5 changed files
with
104 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { GithubService } from "ethpm/storage/github"; | ||
import { URL } from "url"; | ||
import examples from "test/examples/manifests"; | ||
|
||
describe("Github service returns URI contents", () => { | ||
it("with valid blob URI", async () => { | ||
const ownedBlobUri = new URL( | ||
"https://api.github.com/repos/ethpm/ethpm-spec/git/blobs/8f9dc767d4c8b31fec4a08d9c0858d4f37b83180" | ||
); | ||
const service = new GithubService(); | ||
const actualContents = await service.read(ownedBlobUri); | ||
expect(actualContents).toBe(examples.owned); | ||
}); | ||
}); |
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,36 @@ | ||
import { isValidGithubUri } from "ethpm/storage/github"; | ||
import { URL } from "url"; | ||
|
||
const invalidUris = [ | ||
// http is not valid protocol | ||
"http://api.github.com/repos/ethpm/ethpm-spec/git/blobs/123", | ||
// www.github.com is not valid hostname | ||
"https://www.github.com/repos/ethpm/ethpm-spec/git/blobs/123", | ||
// path doesn't contain 'repos' & 'git' & 'blobs' | ||
"https://api.github.com/ethpm/ethpm-spec/git/blobs/123", | ||
"https://api.github.com/repos/ethpm/ethpm-spec/blobs/123", | ||
"https://api.github.com/repos/ethpm/ethpm-spec/git/123" | ||
]; | ||
|
||
const validUris = [ | ||
"https://api.github.com/repos/ethpm/ethpm-spec/git/blobs/123", | ||
"https://api.github.com/repos/other/repository/git/blobs/123" | ||
]; | ||
|
||
invalidUris.forEach(uri => { | ||
describe("Github uri validator invalidates", () => { | ||
it(uri, () => { | ||
const result = isValidGithubUri(new URL(uri)); | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
validUris.forEach(uri => { | ||
describe("Github uri validator validates", () => { | ||
it(uri, () => { | ||
const result = isValidGithubUri(new URL(uri)); | ||
expect(result).toBe(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
/** | ||
* @module "ethpm/storage/github" | ||
* @module "ethpm/storage/github/validation" | ||
*/ | ||
|
||
export default function isValidGithubUri(uri: URL): boolean { | ||
import { URL } from "url"; | ||
|
||
/** | ||
* Returns a bool indicating whether the given uri conforms to this scheme. | ||
* https://api.github.com/repos/:owner/:repo/git/blobs/:file_sha | ||
*/ | ||
export function isValidGithubUri(uri: URL): boolean { | ||
if (uri.hostname != "api.github.com") { | ||
return false; | ||
} | ||
if (uri.protocol != "https:") { | ||
return false; | ||
} | ||
if ( | ||
!uri.pathname.includes("/repos/") || | ||
!uri.pathname.includes("/git/") || | ||
!uri.pathname.includes("/blobs/") | ||
) { | ||
return false; | ||
} | ||
return true; | ||
} |