diff --git a/plugins/core/core/src/software/aws/toolkits/core/utils/SensitiveField.kt b/plugins/core/core/src/software/aws/toolkits/core/utils/SensitiveField.kt index f1d2d37c2b2..1906b9b7708 100644 --- a/plugins/core/core/src/software/aws/toolkits/core/utils/SensitiveField.kt +++ b/plugins/core/core/src/software/aws/toolkits/core/utils/SensitiveField.kt @@ -5,6 +5,7 @@ package software.aws.toolkits.core.utils import kotlin.reflect.full.hasAnnotation import kotlin.reflect.full.memberProperties +import kotlin.reflect.full.superclasses @Target(AnnotationTarget.PROPERTY) annotation class SensitiveField @@ -23,7 +24,13 @@ fun redactedString(o: Any): String { properties.forEachIndexed { i, prop -> append(prop.name) append("=") - if (prop.hasAnnotation()) { + + // @Inherited does not work in Kotlin + // https://youtrack.jetbrains.com/issue/KT-22265/Support-for-inherited-annotations + if ( + prop.hasAnnotation() || + clazz.superclasses.flatMap { superClazz -> superClazz.members.filter { it.name == prop.name } }.any { it.hasAnnotation() } + ) { if (prop.getter.call(o) == null) { append("null") } else { diff --git a/plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/sso/AccessTokenTest.kt b/plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/sso/AccessTokenTest.kt new file mode 100644 index 00000000000..d50e8b80725 --- /dev/null +++ b/plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/sso/AccessTokenTest.kt @@ -0,0 +1,38 @@ +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package software.aws.toolkits.jetbrains.core.credentials.sso + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import java.time.Instant + +class AccessTokenTest { + @Test + fun `DeviceAuthorizationGrantToken#toString has redacted values`() { + val sut = DeviceAuthorizationGrantToken( + startUrl = "clearText", + region = "clearText", + accessToken = "hiddenText", + refreshToken = "hiddenText", + expiresAt = Instant.EPOCH, + createdAt = Instant.EPOCH, + ) + + assertThat(sut.toString()).doesNotContain("hiddenText") + } + + @Test + fun `PKCEAuthorizationGrantToken#toString has redacted values`() { + val sut = PKCEAuthorizationGrantToken( + issuerUrl = "clearText", + region = "clearText", + accessToken = "hiddenText", + refreshToken = "hiddenText", + expiresAt = Instant.EPOCH, + createdAt = Instant.EPOCH, + ) + + assertThat(sut.toString()).doesNotContain("hiddenText") + } +} diff --git a/plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/sso/ClientRegistrationTest.kt b/plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/sso/ClientRegistrationTest.kt new file mode 100644 index 00000000000..2e96112c3dd --- /dev/null +++ b/plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/sso/ClientRegistrationTest.kt @@ -0,0 +1,39 @@ +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package software.aws.toolkits.jetbrains.core.credentials.sso + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import java.time.Instant + +class ClientRegistrationTest { + @Test + fun `DeviceAuthorizationClientRegistration#toString has redacted values`() { + val sut = DeviceAuthorizationClientRegistration( + clientId = "clearText", + clientSecret = "hiddenText", + expiresAt = Instant.EPOCH, + scopes = listOf("clearText"), + ) + + assertThat(sut.toString()).doesNotContain("hiddenText") + } + + @Test + fun `PKCEClientRegistration#toString has redacted values`() { + val sut = PKCEClientRegistration( + clientId = "clearText", + clientSecret = "hiddenText", + expiresAt = Instant.EPOCH, + scopes = listOf("clearText"), + issuerUrl = "clearText", + region = "clearText", + clientType = "clearText", + grantTypes = listOf("clearText"), + redirectUris = listOf("clearText") + ) + + assertThat(sut.toString()).doesNotContain("hiddenText") + } +}