2020-01-06 10:37:12 +00:00
|
|
|
|
import * as path from 'path'
|
2020-01-05 11:55:59 +00:00
|
|
|
|
import * as validate from '../src/validate'
|
|
|
|
|
|
2020-01-11 14:35:09 +00:00
|
|
|
|
const baseDir = path.resolve('.')
|
|
|
|
|
|
|
|
|
|
test('succeeds if all found wrapper jars are valid', async () => {
|
2020-01-15 16:57:46 +00:00
|
|
|
|
const result = await validate.findInvalidWrapperJars(baseDir, 3, false, [
|
2020-01-11 14:35:09 +00:00
|
|
|
|
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(result.isValid()).toBe(true)
|
|
|
|
|
|
|
|
|
|
expect(result.toDisplayString()).toBe(
|
2020-01-13 09:29:20 +00:00
|
|
|
|
'✓ Found known Gradle Wrapper JAR files:\n' +
|
2020-01-15 16:57:46 +00:00
|
|
|
|
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 __tests__/data/invalid/gradle-wrapper.jar\n' +
|
|
|
|
|
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 __tests__/data/invalid/gradlе-wrapper.jar\n' + // homoglyph
|
2020-01-11 14:35:09 +00:00
|
|
|
|
' 3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce __tests__/data/valid/gradle-wrapper.jar'
|
2020-01-06 10:37:12 +00:00
|
|
|
|
)
|
2020-01-11 14:35:09 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('fails if invalid wrapper jars are found', async () => {
|
2020-01-15 16:57:46 +00:00
|
|
|
|
const result = await validate.findInvalidWrapperJars(baseDir, 3, false, [])
|
2020-01-11 14:35:09 +00:00
|
|
|
|
|
|
|
|
|
expect(result.isValid()).toBe(false)
|
|
|
|
|
|
|
|
|
|
expect(result.valid).toEqual([
|
|
|
|
|
new validate.WrapperJar(
|
|
|
|
|
'__tests__/data/valid/gradle-wrapper.jar',
|
|
|
|
|
'3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce'
|
|
|
|
|
)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(result.invalid).toEqual([
|
|
|
|
|
new validate.WrapperJar(
|
2020-01-06 12:50:19 +00:00
|
|
|
|
'__tests__/data/invalid/gradle-wrapper.jar',
|
|
|
|
|
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
2020-01-15 16:57:46 +00:00
|
|
|
|
),
|
|
|
|
|
new validate.WrapperJar(
|
|
|
|
|
'__tests__/data/invalid/gradlе-wrapper.jar', // homoglyph
|
|
|
|
|
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
2020-01-06 12:50:19 +00:00
|
|
|
|
)
|
2020-01-11 14:35:09 +00:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(result.toDisplayString()).toBe(
|
2020-01-13 09:29:20 +00:00
|
|
|
|
'✗ Found unknown Gradle Wrapper JAR files:\n' +
|
2020-01-15 16:57:46 +00:00
|
|
|
|
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 __tests__/data/invalid/gradle-wrapper.jar\n' +
|
|
|
|
|
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 __tests__/data/invalid/gradlе-wrapper.jar\n' + // homoglyph
|
2020-01-13 09:29:20 +00:00
|
|
|
|
'✓ Found known Gradle Wrapper JAR files:\n' +
|
2020-01-11 14:35:09 +00:00
|
|
|
|
' 3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce __tests__/data/valid/gradle-wrapper.jar'
|
2020-01-06 10:37:12 +00:00
|
|
|
|
)
|
2020-01-05 11:55:59 +00:00
|
|
|
|
})
|
2020-01-10 16:54:22 +00:00
|
|
|
|
|
|
|
|
|
test('fails if not enough wrapper jars are found', async () => {
|
2020-01-15 16:57:46 +00:00
|
|
|
|
const result = await validate.findInvalidWrapperJars(baseDir, 4, false, [])
|
2020-01-11 14:35:09 +00:00
|
|
|
|
|
|
|
|
|
expect(result.isValid()).toBe(false)
|
|
|
|
|
|
|
|
|
|
expect(result.errors).toEqual([
|
2020-01-13 17:39:40 +00:00
|
|
|
|
'Expected to find at least 4 Gradle Wrapper JARs but got only 3'
|
2020-01-11 14:35:09 +00:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
expect(result.toDisplayString()).toBe(
|
2020-01-13 09:29:20 +00:00
|
|
|
|
'✗ Found unknown Gradle Wrapper JAR files:\n' +
|
2020-01-15 16:57:46 +00:00
|
|
|
|
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 __tests__/data/invalid/gradle-wrapper.jar\n' +
|
|
|
|
|
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 __tests__/data/invalid/gradlе-wrapper.jar\n' + // homoglyph
|
2020-01-13 09:29:20 +00:00
|
|
|
|
'✗ Other validation errors:\n' +
|
2020-01-15 16:57:46 +00:00
|
|
|
|
' Expected to find at least 4 Gradle Wrapper JARs but got only 3\n' +
|
2020-01-13 09:29:20 +00:00
|
|
|
|
'✓ Found known Gradle Wrapper JAR files:\n' +
|
2020-01-11 14:35:09 +00:00
|
|
|
|
' 3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce __tests__/data/valid/gradle-wrapper.jar'
|
2020-01-10 16:59:23 +00:00
|
|
|
|
)
|
2020-01-10 16:54:22 +00:00
|
|
|
|
})
|