mirror of
https://github.com/gradle/actions.git
synced 2025-08-22 01:31:28 +08:00
The checksum values for most wrapper versions are hard-coded into the action. These known checksum values are first used for validation: only if none of the known values work do we download checksums. Previously, we blindly downloaded all of the checksum values in this case: we now only download the checksums for versions that are not in our "known" set. Fixes #171
101 lines
4.2 KiB
TypeScript
101 lines
4.2 KiB
TypeScript
import * as path from 'path'
|
||
import * as validate from '../../../src/wrapper-validation/validate'
|
||
import {expect, test, jest} from '@jest/globals'
|
||
import { WrapperChecksums } from '../../../src/wrapper-validation/checksums'
|
||
|
||
jest.setTimeout(30000)
|
||
|
||
const baseDir = path.resolve('./test/jest/wrapper-validation')
|
||
|
||
test('succeeds if all found wrapper jars are valid', async () => {
|
||
const result = await validate.findInvalidWrapperJars(baseDir, 3, false, [
|
||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
||
])
|
||
|
||
expect(result.isValid()).toBe(true)
|
||
// Only hardcoded and explicitly allowed checksums should have been used
|
||
expect(result.fetchedChecksums).toBe(false)
|
||
|
||
expect(result.toDisplayString()).toBe(
|
||
'✓ Found known Gradle Wrapper JAR files:\n' +
|
||
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/invalid/gradle-wrapper.jar\n' +
|
||
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/invalid/gradlе-wrapper.jar\n' + // homoglyph
|
||
' 3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce data/valid/gradle-wrapper.jar'
|
||
)
|
||
})
|
||
|
||
test('succeeds if all found wrapper jars are valid (and checksums are fetched from Gradle API)', async () => {
|
||
const knownValidChecksums = new WrapperChecksums()
|
||
const result = await validate.findInvalidWrapperJars(
|
||
baseDir,
|
||
1,
|
||
false,
|
||
['e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'],
|
||
knownValidChecksums
|
||
)
|
||
console.log(`fetchedChecksums = ${result.fetchedChecksums}`)
|
||
|
||
expect(result.isValid()).toBe(true)
|
||
// Should have fetched checksums because no known checksums were provided
|
||
expect(result.fetchedChecksums).toBe(true)
|
||
|
||
expect(result.toDisplayString()).toBe(
|
||
'✓ Found known Gradle Wrapper JAR files:\n' +
|
||
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/invalid/gradle-wrapper.jar\n' +
|
||
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/invalid/gradlе-wrapper.jar\n' + // homoglyph
|
||
' 3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce data/valid/gradle-wrapper.jar'
|
||
)
|
||
})
|
||
|
||
test('fails if invalid wrapper jars are found', async () => {
|
||
const result = await validate.findInvalidWrapperJars(baseDir, 3, false, [])
|
||
|
||
expect(result.isValid()).toBe(false)
|
||
|
||
expect(result.valid).toEqual([
|
||
new validate.WrapperJar(
|
||
'data/valid/gradle-wrapper.jar',
|
||
'3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce'
|
||
)
|
||
])
|
||
|
||
expect(result.invalid).toEqual([
|
||
new validate.WrapperJar(
|
||
'data/invalid/gradle-wrapper.jar',
|
||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
||
),
|
||
new validate.WrapperJar(
|
||
'data/invalid/gradlе-wrapper.jar', // homoglyph
|
||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
||
)
|
||
])
|
||
|
||
expect(result.toDisplayString()).toBe(
|
||
'✗ Found unknown Gradle Wrapper JAR files:\n' +
|
||
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/invalid/gradle-wrapper.jar\n' +
|
||
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/invalid/gradlе-wrapper.jar\n' + // homoglyph
|
||
'✓ Found known Gradle Wrapper JAR files:\n' +
|
||
' 3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce data/valid/gradle-wrapper.jar'
|
||
)
|
||
})
|
||
|
||
test('fails if not enough wrapper jars are found', async () => {
|
||
const result = await validate.findInvalidWrapperJars(baseDir, 4, false, [])
|
||
|
||
expect(result.isValid()).toBe(false)
|
||
|
||
expect(result.errors).toEqual([
|
||
'Expected to find at least 4 Gradle Wrapper JARs but got only 3'
|
||
])
|
||
|
||
expect(result.toDisplayString()).toBe(
|
||
'✗ Found unknown Gradle Wrapper JAR files:\n' +
|
||
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/invalid/gradle-wrapper.jar\n' +
|
||
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/invalid/gradlе-wrapper.jar\n' + // homoglyph
|
||
'✗ Other validation errors:\n' +
|
||
' Expected to find at least 4 Gradle Wrapper JARs but got only 3\n' +
|
||
'✓ Found known Gradle Wrapper JAR files:\n' +
|
||
' 3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce data/valid/gradle-wrapper.jar'
|
||
)
|
||
})
|