Skip to content

Commit 32d7247

Browse files
authored
Merge pull request #44 from codingtools/fix/validating-hashing-issue-34
Fix/validating hashing issue 34
2 parents aff1c64 + 918bd6e commit 32d7247

File tree

7 files changed

+64
-12
lines changed

7 files changed

+64
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
node_modules
99
/.idea
1010
cdt.iml
11+
**/.DS_Store

package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"axios": "^0.19.0",
2020
"chalk": "^3.0.0",
2121
"crypto-js": "^3.1.9-1",
22+
"detect-character-encoding": "^0.8.0",
23+
"encoding-japanese": "^1.0.30",
2224
"jshashes": "^1.0.7",
2325
"minify": "^4.1.3",
2426
"moment": "^2.24.0",

src/commands/hash.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Command, flags} from '@oclif/command'
22
import * as CryptoJS from 'crypto-js'
3-
// @ts-ignore
3+
// import * as Hashes from 'jshashes'
44

55
import Logger from '../utilities/logger'
66
import Utilities from '../utilities/utilities'
@@ -57,19 +57,19 @@ export default class Hash extends Command {
5757
Logger.success(this, `[${flags.type.toUpperCase()}] ${hashed}`)
5858
}
5959

60-
// import * as Hashes from 'jshashes'
61-
// private getHashObjectBCK(flags: any) {
60+
// BACKUP function
61+
// private getHashObject2(flags: any) {
6262
// switch (flags.type.toUpperCase()) {
6363
// case 'SHA1':
64-
// return new Hashes.SHA1()
64+
// return new Hashes.SHA1().hex
6565
// case 'SHA256':
66-
// return new Hashes.SHA256()
66+
// return new Hashes.SHA256().hex
6767
// case 'SHA512':
68-
// return new Hashes.SHA512()
68+
// return new Hashes.SHA512().hex
6969
// case 'MD5':
70-
// return new Hashes.MD5()
70+
// return new Hashes.MD5().hex
7171
// case 'RMD160':
72-
// return new Hashes.RMD160()
72+
// return new Hashes.RMD160().hex
7373
// default:
7474
// Logger.error(this, 'Invalid Or Unsupported hash type')
7575
// }

src/utilities/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default class Utilities {
99
if (!fs.existsSync(filePath)) {
1010
Logger.error(thisRef, `Could not find file: ${filePath}`) // this will output error and exit command
1111
} else {
12-
fileStr = fs.readFileSync(filePath, 'utf8')
13-
12+
let fileBuffer = fs.readFileSync(filePath)
13+
fileStr = fileBuffer.toString() // by default utf8
1414
}
1515
return fileStr
1616
}

test/commands/hash.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ describe('hash', () => {
2222
.stdout()
2323
.command(['hash', '-t', 'md5'])
2424
.exit(0)
25-
.it("Empty Input String -> cdt hash -t md5", ctx => {
25+
.it('Empty Input String -> cdt hash -t md5', ctx => {
2626
expect(ctx.stdout).to.contain('Input string is empty or undefined')
2727
})
2828

29-
3029
// passing sha1 as option
3130
test
3231
.stdout()
@@ -107,4 +106,22 @@ describe('hash', () => {
107106
.it("If File not found ->cdt hash -f 'test/resources/filenotfound.txt'", ctx => {
108107
expect(ctx.stdout).to.contain('Could not find file')
109108
})
109+
110+
// TODO: fix this issue
111+
// //installer file - checksum check sha1
112+
// test
113+
// .stdout()
114+
// .command(['hash', '-t', 'sha1', '-f', 'test/resources/apache-maven-3.6.3-src.tar.gz'])
115+
// .it('Installer checksum validation', ctx => {
116+
// expect(ctx.stdout).to.contain('ccf441f3bf7f477301ebc80742cbda1da73c30a2')
117+
// })
118+
119+
// //installer file - checksum check sha512
120+
// test
121+
// .stdout()
122+
// .command(['hash', '-t', 'sha512', '-f', 'test/resources/apache-maven-3.6.3-src.tar.gz'])
123+
// .it('Installer checksum validation', ctx => {
124+
// expect(ctx.stdout).to.contain('14eef64ad13c1f689f2ab0d2b2b66c9273bf336e557d81d5c22ddb001c47cf51f03bb1465d6059ce9fdc2e43180ceb0638ce914af1f53af9c2398f5d429f114c')
125+
// })
126+
110127
})
2.63 MB
Binary file not shown.

0 commit comments

Comments
 (0)