Skip to content

Commit 728b3b2

Browse files
committed
Merge branch 'release/release-v0.1' of github.com:codingtools/cdt into release/release-v0.1
2 parents a880b22 + 5c7891d commit 728b3b2

File tree

8 files changed

+2404
-13
lines changed

8 files changed

+2404
-13
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
node_modules
99
/.idea
1010
cdt.iml
11-
.DS_Store
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: 27 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()
@@ -91,6 +90,14 @@ describe('hash', () => {
9190
expect(ctx.stdout).to.contain('d246b69fd991a1256f9e00f6914c8bd2d52b432e')
9291
})
9392

93+
//Big file input
94+
test
95+
.stdout()
96+
.command(['hash', '-t', 'sha512', '-f', 'test/resources/react.js']) //75KB
97+
.it("File Hashing -> cdt hash -f 'test/resources/react.js' -t 'sha512'", ctx => {
98+
expect(ctx.stdout).to.contain('74886dc316093bad0732f29dba9117cff013ad4488c6fa15bae44b9d0cbb2e5e9e12a3af1a112f3027629a9224b324ba882e4d0c1286f9d5d0ded1d44ebb65cb')
99+
})
100+
94101
//file input sha512
95102
test
96103
.stdout()
@@ -107,4 +114,22 @@ describe('hash', () => {
107114
.it("If File not found ->cdt hash -f 'test/resources/filenotfound.txt'", ctx => {
108115
expect(ctx.stdout).to.contain('Could not find file')
109116
})
117+
118+
// TODO: fix this issue
119+
// //installer file - checksum check sha1
120+
// test
121+
// .stdout()
122+
// .command(['hash', '-t', 'sha1', '-f', 'test/resources/apache-maven-3.6.3-src.tar.gz'])
123+
// .it('Installer checksum validation', ctx => {
124+
// expect(ctx.stdout).to.contain('ccf441f3bf7f477301ebc80742cbda1da73c30a2')
125+
// })
126+
127+
// //installer file - checksum check sha512
128+
// test
129+
// .stdout()
130+
// .command(['hash', '-t', 'sha512', '-f', 'test/resources/apache-maven-3.6.3-src.tar.gz'])
131+
// .it('Installer checksum validation', ctx => {
132+
// expect(ctx.stdout).to.contain('14eef64ad13c1f689f2ab0d2b2b66c9273bf336e557d81d5c22ddb001c47cf51f03bb1465d6059ce9fdc2e43180ceb0638ce914af1f53af9c2398f5d429f114c')
133+
// })
134+
110135
})
2.63 MB
Binary file not shown.

0 commit comments

Comments
 (0)