Skip to content

Commit

Permalink
- update and introduce testcases for the new configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Jan 25, 2024
1 parent f7d3b94 commit 27b277e
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
15 changes: 13 additions & 2 deletions __tests__/checksums.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ import {afterEach, describe, expect, test, jest} from '@jest/globals'
jest.setTimeout(30000)

test('fetches wrapper jars checksums', async () => {
const validChecksums = await checksums.fetchValidChecksums(false)
const validChecksums = await checksums.fetchValidChecksums(false, false, [])
expect(validChecksums.length).toBeGreaterThan(10)
})

test('fetches wrapper jars checksums only for detected versions', async () => {
const validChecksums = await checksums.fetchValidChecksums(false, true, [
'8.2.1'
])
expect(validChecksums.length).toBe(1)
})

describe('retry', () => {
afterEach(() => {
nock.cleanAll()
Expand All @@ -24,7 +31,11 @@ describe('retry', () => {
code: 'ECONNREFUSED'
})

const validChecksums = await checksums.fetchValidChecksums(false)
const validChecksums = await checksums.fetchValidChecksums(
false,
false,
[]
)
expect(validChecksums.length).toBeGreaterThan(10)
nock.isDone()
})
Expand Down
7 changes: 7 additions & 0 deletions __tests__/data/invalid/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle8.2.1bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
5 changes: 5 additions & 0 deletions __tests__/data/valid/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-milestone-3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
10 changes: 10 additions & 0 deletions __tests__/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ test('finds test data wrapper jars', async () => {
expect(wrapperJars).toContain('__tests__/data/invalid/gradle-wrapper.jar')
expect(wrapperJars).toContain('__tests__/data/invalid/gradlе-wrapper.jar') // homoglyph
})

test('detect version from `gradle-wrapper.properties` alongside wrappers', async () => {
const repoRoot = path.resolve('.')
const wrapperJars = await find.findWrapperJars(repoRoot)

const detectedVersions = await find.detectVersions(wrapperJars)

expect(detectedVersions.length).toBe(1)
expect(detectedVersions).toContain('6.1-milestone-3')
})
64 changes: 59 additions & 5 deletions __tests__/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ jest.setTimeout(30000)
const baseDir = path.resolve('.')

test('succeeds if all found wrapper jars are valid', async () => {
const result = await validate.findInvalidWrapperJars(baseDir, 3, false, [
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
])
const result = await validate.findInvalidWrapperJars(
baseDir,
3,
false,
['e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'],
false
)

expect(result.isValid()).toBe(true)

Expand All @@ -22,7 +26,51 @@ test('succeeds if all found wrapper jars are valid', async () => {
})

test('fails if invalid wrapper jars are found', async () => {
const result = await validate.findInvalidWrapperJars(baseDir, 3, false, [])
const result = await validate.findInvalidWrapperJars(
baseDir,
3,
false,
[],
false
)

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(
'__tests__/data/invalid/gradle-wrapper.jar',
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
),
new validate.WrapperJar(
'__tests__/data/invalid/gradlе-wrapper.jar', // homoglyph
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
)
])

expect(result.toDisplayString()).toBe(
'✗ Found unknown Gradle Wrapper JAR files:\n' +
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 __tests__/data/invalid/gradle-wrapper.jar\n' +
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 __tests__/data/invalid/gradlе-wrapper.jar\n' + // homoglyph
'✓ Found known Gradle Wrapper JAR files:\n' +
' 3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce __tests__/data/valid/gradle-wrapper.jar'
)
})

test('fails if invalid wrapper jars are found when detection versions from `gradle-wrapper.properties`', async () => {
const result = await validate.findInvalidWrapperJars(
baseDir,
3,
false,
[],
true
)

expect(result.isValid()).toBe(false)

Expand Down Expand Up @@ -54,7 +102,13 @@ test('fails if invalid wrapper jars are found', async () => {
})

test('fails if not enough wrapper jars are found', async () => {
const result = await validate.findInvalidWrapperJars(baseDir, 4, false, [])
const result = await validate.findInvalidWrapperJars(
baseDir,
4,
false,
[],
false
)

expect(result.isValid()).toBe(false)

Expand Down

0 comments on commit 27b277e

Please sign in to comment.