-
Notifications
You must be signed in to change notification settings - Fork 54
Get a list of files, get some hashes, talk to some people, have a good day #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
DarthHater
wants to merge
17
commits into
alpha
Choose a base branch
from
HashHouseAGogo
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1731f83
Lister
DarthHater bb14902
Be more descriptive
DarthHater 334be02
Hasher
DarthHater 765bc73
Start wiring hasher and lister
DarthHater 35ed0c3
Merge hashes and sbom
DarthHater f8bd6e4
Ok tuned down to just scan bin for now
DarthHater 5c7e4b8
Return path, add in algorithm, default to SHA-1, fix test
DarthHater e0784f9
Ok wired up
DarthHater e6cb5f6
Add in logging
DarthHater de292b3
Some tweaks, tested against 83 and at least getting it accepted, no r…
DarthHater 6f1f901
removed the submitForEvaluation function as it is no longer being use…
21044a1
scaffolding for merger tests
allenhsieh 48c1ab8
Dummy thicc version
DarthHater 0d6879a
Merge branch 'HashHouseAGogo' of github.com:sonatype-nexus-community/…
DarthHater fb42434
Help with test a lil bit
DarthHater 021a0c4
passing test for merger
allenhsieh 0b8526e
added Merger rejection test
allenhsieh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
| /* | ||
| * Copyright (c) 2020-present Sonatype, Inc. | ||
| * | ||
| * 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 expect from '../Tests/TestHelper'; | ||
| import { Hasher } from './Hasher'; | ||
| import mock from 'mock-fs'; | ||
|
|
||
| const json = `{"thing": "value"}`; | ||
|
|
||
| const json2 = `{"anotherThing": "anotherValue"}`; | ||
|
|
||
| const json3 = `{"yetAnotherThing": "yetAnotherValue"}`; | ||
|
|
||
| describe("Hasher", () => { | ||
| it("should return a sha1 hash for a provided path", async () => { | ||
| mock({'/nonsensical': { | ||
| 'auditjs.js': json, | ||
| 'directory': { | ||
| 'anotherpath.js': json2, | ||
| 'fakething.js': json3, | ||
| 'anotherdirectory': {} | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| let expected = '54bbc009e6ba2ee4e892a0347279819bd30e5e29'; | ||
|
|
||
| let hasher = new Hasher('sha1'); | ||
|
|
||
| let result = await hasher.getHashFromPath('/nonsensical/auditjs.js'); | ||
|
|
||
| expect(result) | ||
| .to.eq(expected); | ||
|
|
||
| mock.restore(); | ||
| }); | ||
| }); |
This file contains hidden or 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,41 @@ | ||
| /* | ||
| * Copyright (c) 2020-present Sonatype, Inc. | ||
| * | ||
| * 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 fs from 'fs'; | ||
| import crypto from 'crypto'; | ||
|
|
||
| export class Hasher { | ||
| constructor(readonly algorithm: string = 'sha1') {} | ||
|
|
||
| public getHashFromPath(path: string): Promise<string> { | ||
| return new Promise((resolve, reject) => { | ||
| let fd = fs.createReadStream(path); | ||
| let hash = crypto.createHash(this.algorithm); | ||
| hash.setEncoding('hex'); | ||
|
|
||
| fd.on('end', () => { | ||
| hash.end(); | ||
| resolve(hash.read()); | ||
| }); | ||
|
|
||
| fd.on('error', (err) => { | ||
| reject(err); | ||
| }); | ||
|
|
||
| fd.pipe(hash); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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,44 @@ | ||
| /* | ||
| * Copyright (c) 2020-present Sonatype, Inc. | ||
| * | ||
| * 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 expect from '../Tests/TestHelper'; | ||
| import { Lister } from './Lister'; | ||
| import mock from 'mock-fs'; | ||
|
|
||
| describe("Lister", () => { | ||
| it("should return a set of paths to js files and no directories given a base path", async () => { | ||
| mock({'/nonsensical': { | ||
| 'auditjs.js': '{}', | ||
| 'directory': { | ||
| 'anotherpath.js': '{}', | ||
| 'fakething.notjs': '{}', | ||
| 'anotherdirectory': {} | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| let expected = new Set(); | ||
|
|
||
| expected.add('auditjs.js'); | ||
| expected.add('directory/anotherpath.js'); | ||
|
|
||
| let result = Lister.getListOfFilesInBasePath('/nonsensical'); | ||
|
|
||
| expect(result) | ||
| .to.deep.eq(expected); | ||
|
|
||
| mock.restore(); | ||
| }); | ||
| }); |
This file contains hidden or 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,24 @@ | ||
| /* | ||
| * Copyright (c) 2020-present Sonatype, Inc. | ||
| * | ||
| * 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 glob from 'glob'; | ||
|
|
||
| export abstract class Lister { | ||
| public static getListOfFilesInBasePath(path: string): Set<string> { | ||
| let files = glob.sync(`**/*.js`, {nodir: true, cwd: path}); | ||
|
|
||
| return new Set(files); | ||
| } | ||
| } |
This file contains hidden or 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,38 @@ | ||
| /* | ||
| * Copyright (c) 2020-present Sonatype, Inc. | ||
| * | ||
| * 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 elementtree from 'elementtree'; | ||
|
|
||
| export class Merger { | ||
| public async mergeHashesIntoSbom(hashes: string[], xml: string): Promise<string> { | ||
| return new Promise((resolve, reject) => { | ||
| let tree = elementtree.parse(xml); | ||
| let components = tree.find('./components'); | ||
| if (!components) { | ||
| reject(); | ||
| } | ||
| hashes.map((val) => { | ||
| if (components) { | ||
| let component = elementtree.SubElement(components, 'component') | ||
| let name = elementtree.SubElement(component, 'name'); | ||
| let version = elementtree.SubElement(component, 'version'); | ||
| let hash = elementtree.SubElement(component, 'hash'); | ||
| hash.text = val; | ||
| } | ||
| }); | ||
| resolve(tree.write()); | ||
| }); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.