Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
node_modules
/.idea
cdt.iml
**/.DS_Store
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"axios": "^0.19.0",
"chalk": "^3.0.0",
"crypto-js": "^3.1.9-1",
"detect-character-encoding": "^0.8.0",
"encoding-japanese": "^1.0.30",
"jshashes": "^1.0.7",
"minify": "^4.1.3",
"moment": "^2.24.0",
Expand Down
16 changes: 8 additions & 8 deletions src/commands/hash.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Command, flags} from '@oclif/command'
import * as CryptoJS from 'crypto-js'
// @ts-ignore
// import * as Hashes from 'jshashes'

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

// import * as Hashes from 'jshashes'
// private getHashObjectBCK(flags: any) {
// BACKUP function
// private getHashObject2(flags: any) {
// switch (flags.type.toUpperCase()) {
// case 'SHA1':
// return new Hashes.SHA1()
// return new Hashes.SHA1().hex
// case 'SHA256':
// return new Hashes.SHA256()
// return new Hashes.SHA256().hex
// case 'SHA512':
// return new Hashes.SHA512()
// return new Hashes.SHA512().hex
// case 'MD5':
// return new Hashes.MD5()
// return new Hashes.MD5().hex
// case 'RMD160':
// return new Hashes.RMD160()
// return new Hashes.RMD160().hex
// default:
// Logger.error(this, 'Invalid Or Unsupported hash type')
// }
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default class Utilities {
if (!fs.existsSync(filePath)) {
Logger.error(thisRef, `Could not find file: ${filePath}`) // this will output error and exit command
} else {
fileStr = fs.readFileSync(filePath, 'utf8')

let fileBuffer = fs.readFileSync(filePath)
fileStr = fileBuffer.toString() // by default utf8
}
return fileStr
}
Expand Down
21 changes: 19 additions & 2 deletions test/commands/hash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ describe('hash', () => {
.stdout()
.command(['hash', '-t', 'md5'])
.exit(0)
.it("Empty Input String -> cdt hash -t md5", ctx => {
.it('Empty Input String -> cdt hash -t md5', ctx => {
expect(ctx.stdout).to.contain('Input string is empty or undefined')
})


// passing sha1 as option
test
.stdout()
Expand Down Expand Up @@ -107,4 +106,22 @@ describe('hash', () => {
.it("If File not found ->cdt hash -f 'test/resources/filenotfound.txt'", ctx => {
expect(ctx.stdout).to.contain('Could not find file')
})

// TODO: fix this issue
// //installer file - checksum check sha1
// test
// .stdout()
// .command(['hash', '-t', 'sha1', '-f', 'test/resources/apache-maven-3.6.3-src.tar.gz'])
// .it('Installer checksum validation', ctx => {
// expect(ctx.stdout).to.contain('ccf441f3bf7f477301ebc80742cbda1da73c30a2')
// })

// //installer file - checksum check sha512
// test
// .stdout()
// .command(['hash', '-t', 'sha512', '-f', 'test/resources/apache-maven-3.6.3-src.tar.gz'])
// .it('Installer checksum validation', ctx => {
// expect(ctx.stdout).to.contain('14eef64ad13c1f689f2ab0d2b2b66c9273bf336e557d81d5c22ddb001c47cf51f03bb1465d6059ce9fdc2e43180ceb0638ce914af1f53af9c2398f5d429f114c')
// })

})
Binary file added test/resources/apache-maven-3.6.3-src.tar.gz
Binary file not shown.