Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +24,13 @@ fun redactedString(o: Any): String {
properties.forEachIndexed { i, prop ->
append(prop.name)
append("=")
if (prop.hasAnnotation<SensitiveField>()) {

// @Inherited does not work in Kotlin
// https://youtrack.jetbrains.com/issue/KT-22265/Support-for-inherited-annotations
if (
prop.hasAnnotation<SensitiveField>() ||
clazz.superclasses.flatMap { superClazz -> superClazz.members.filter { it.name == prop.name } }.any { it.hasAnnotation<SensitiveField>() }
) {
if (prop.getter.call(o) == null) {
append("null")
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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")
}
}
Loading