Skip to content

Commit

Permalink
fix: Address compile warnings on custom Truth subjects (#275)
Browse files Browse the repository at this point in the history
These were introduced when the Truth version was upgraded in #268.
  • Loading branch information
SanjayVas authored Sep 23, 2024
1 parent 0b843d2 commit 92d80e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ import org.wfanet.measurement.common.crypto.SignatureAlgorithm
import org.wfanet.measurement.common.crypto.subjectKeyIdentifier
import org.wfanet.measurement.common.crypto.verifySignature

class SignatureSubject private constructor(failureMetadata: FailureMetadata, subject: ByteString) :
Subject(failureMetadata, subject) {

private val actual = subject
class SignatureSubject
private constructor(failureMetadata: FailureMetadata, private val actual: ByteString?) :
Subject(failureMetadata, actual) {

fun isValidFor(certificate: X509Certificate, algorithm: SignatureAlgorithm, data: ByteString) {
if (actual == null) {
failWithActual(Fact.simpleFact("expected not to be null"))
return
}

if (!certificate.verifySignature(algorithm, data, actual)) {
failWithActual(
Fact.simpleFact("cannot be verified"),
Fact.fact("certificate SKID", certificate.subjectKeyIdentifier),
Fact.fact("data", data)
Fact.fact("data", data),
)
}
}
Expand All @@ -45,7 +49,9 @@ class SignatureSubject private constructor(failureMetadata: FailureMetadata, sub
fun assertThat(actual: ByteString): SignatureSubject =
Truth.assertAbout(signatures()).that(actual)

fun signatures(): (failureMetadata: FailureMetadata, subject: ByteString) -> SignatureSubject =
::SignatureSubject
fun signatures() =
Factory<SignatureSubject, ByteString> { metadata, actual ->
SignatureSubject(metadata, actual)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@ object CommandLineTesting {
assertAbout(CapturedOutputSubject.capturedOutputs()).that(actual)

class CapturedOutputSubject
private constructor(
metadata: FailureMetadata,
private val actual: CapturedOutput,
) : Subject(metadata, actual) {
private constructor(metadata: FailureMetadata, private val actual: CapturedOutput?) :
Subject(metadata, actual) {
fun status(): IntegerSubject {
return check("status").that(actual.status)
return check("status").that(actual?.status)
}

fun out(): StringSubject {
return check("out").that(actual.out)
return check("out").that(actual?.out)
}

fun err(): StringSubject {
return check("err").that(actual.err)
return check("err").that(actual?.err)
}

companion object {
fun capturedOutputs(): (FailureMetadata, CapturedOutput) -> CapturedOutputSubject =
::CapturedOutputSubject
fun capturedOutputs() =
Factory<CapturedOutputSubject, CapturedOutput> { metadata, actual ->
CapturedOutputSubject(metadata, actual)
}
}
}
}
Expand All @@ -103,6 +103,7 @@ object ExitInterceptingSecurityManager : SecurityManager() {
override fun checkPermission(perm: Permission?) {
// Allow everything.
}

override fun checkExit(status: Int) {
super.checkExit(status)

Expand Down

0 comments on commit 92d80e4

Please sign in to comment.