|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -16,12 +16,12 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.endpoint;
|
|
|
|
|
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
|
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -49,14 +49,15 @@ class SanitizerTests {
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "key = {0}")
|
|
|
|
|
@MethodSource("matchingUriUserInfoKeys")
|
|
|
|
|
void uriWithSingleEntryWithPasswordShouldBeSanitized(String key) {
|
|
|
|
|
void uriWithSingleValueWithPasswordShouldBeSanitized(String key) {
|
|
|
|
|
Sanitizer sanitizer = new Sanitizer();
|
|
|
|
|
assertThat(sanitizer.sanitize(key, "http://user:password@localhost:8080")).isEqualTo("http://user:******@localhost:8080");
|
|
|
|
|
assertThat(sanitizer.sanitize(key, "http://user:password@localhost:8080"))
|
|
|
|
|
.isEqualTo("http://user:******@localhost:8080");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "key = {0}")
|
|
|
|
|
@MethodSource("matchingUriUserInfoKeys")
|
|
|
|
|
void uriWithSingleEntryWithNoPasswordShouldNotBeSanitized(String key) {
|
|
|
|
|
void uriWithSingleValueWithNoPasswordShouldNotBeSanitized(String key) {
|
|
|
|
|
Sanitizer sanitizer = new Sanitizer();
|
|
|
|
|
assertThat(sanitizer.sanitize(key, "http://localhost:8080")).isEqualTo("http://localhost:8080");
|
|
|
|
|
assertThat(sanitizer.sanitize(key, "http://user@localhost:8080")).isEqualTo("http://user@localhost:8080");
|
|
|
|
@ -64,22 +65,24 @@ class SanitizerTests {
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "key = {0}")
|
|
|
|
|
@MethodSource("matchingUriUserInfoKeys")
|
|
|
|
|
void uriWithSingleEntryWithPasswordMatchingOtherPartsOfStringShouldBeSanitized(String key) {
|
|
|
|
|
void uriWithSingleValueWithPasswordMatchingOtherPartsOfStringShouldBeSanitized(String key) {
|
|
|
|
|
Sanitizer sanitizer = new Sanitizer();
|
|
|
|
|
assertThat(sanitizer.sanitize(key, "http://user://@localhost:8080")).isEqualTo("http://user:******@localhost:8080");
|
|
|
|
|
assertThat(sanitizer.sanitize(key, "http://user://@localhost:8080"))
|
|
|
|
|
.isEqualTo("http://user:******@localhost:8080");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "key = {0}")
|
|
|
|
|
@MethodSource("matchingUriUserInfoKeys")
|
|
|
|
|
void uriWithMultipleEntriesEachWithPasswordShouldHaveAllSanitized(String key) {
|
|
|
|
|
void uriWithMultipleValuesEachWithPasswordShouldHaveAllSanitized(String key) {
|
|
|
|
|
Sanitizer sanitizer = new Sanitizer();
|
|
|
|
|
assertThat(sanitizer.sanitize(key, "http://user1:password1@localhost:8080,http://user2:password2@localhost:8082"))
|
|
|
|
|
.isEqualTo("http://user1:******@localhost:8080,http://user2:******@localhost:8082");
|
|
|
|
|
assertThat(
|
|
|
|
|
sanitizer.sanitize(key, "http://user1:password1@localhost:8080,http://user2:password2@localhost:8082"))
|
|
|
|
|
.isEqualTo("http://user1:******@localhost:8080,http://user2:******@localhost:8082");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "key = {0}")
|
|
|
|
|
@MethodSource("matchingUriUserInfoKeys")
|
|
|
|
|
void uriWithMultipleEntriesNoneWithPasswordShouldHaveNoneSanitized(String key) {
|
|
|
|
|
void uriWithMultipleValuesNoneWithPasswordShouldHaveNoneSanitized(String key) {
|
|
|
|
|
Sanitizer sanitizer = new Sanitizer();
|
|
|
|
|
assertThat(sanitizer.sanitize(key, "http://user@localhost:8080,http://localhost:8082"))
|
|
|
|
|
.isEqualTo("http://user@localhost:8080,http://localhost:8082");
|
|
|
|
@ -87,22 +90,24 @@ class SanitizerTests {
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "key = {0}")
|
|
|
|
|
@MethodSource("matchingUriUserInfoKeys")
|
|
|
|
|
void uriWithMultipleEntriesSomeWithPasswordShouldHaveThoseSanitized(String key) {
|
|
|
|
|
void uriWithMultipleValuesSomeWithPasswordShouldHaveThoseSanitized(String key) {
|
|
|
|
|
Sanitizer sanitizer = new Sanitizer();
|
|
|
|
|
assertThat(sanitizer.sanitize(key, "http://user1:password1@localhost:8080,http://user2@localhost:8082,http://localhost:8083"))
|
|
|
|
|
.isEqualTo("http://user1:******@localhost:8080,http://user2@localhost:8082,http://localhost:8083");
|
|
|
|
|
assertThat(sanitizer.sanitize(key,
|
|
|
|
|
"http://user1:password1@localhost:8080,http://user2@localhost:8082,http://localhost:8083")).isEqualTo(
|
|
|
|
|
"http://user1:******@localhost:8080,http://user2@localhost:8082,http://localhost:8083");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "key = {0}")
|
|
|
|
|
@MethodSource("matchingUriUserInfoKeys")
|
|
|
|
|
void uriWithMultipleEntriesWithPasswordMatchingOtherPartsOfStringShouldBeSanitized(String key) {
|
|
|
|
|
void uriWithMultipleValuesWithPasswordMatchingOtherPartsOfStringShouldBeSanitized(String key) {
|
|
|
|
|
Sanitizer sanitizer = new Sanitizer();
|
|
|
|
|
assertThat(sanitizer.sanitize(key, "http://user1://@localhost:8080,http://user2://@localhost:8082"))
|
|
|
|
|
.isEqualTo("http://user1:******@localhost:8080,http://user2:******@localhost:8082");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static private Stream<String> matchingUriUserInfoKeys() {
|
|
|
|
|
return Stream.of("uri", "my.uri", "myuri", "uris", "my.uris", "myuris", "address", "my.address", "myaddress", "addresses", "my.addresses", "myaddresses");
|
|
|
|
|
private static Stream<String> matchingUriUserInfoKeys() {
|
|
|
|
|
return Stream.of("uri", "my.uri", "myuri", "uris", "my.uris", "myuris", "address", "my.address", "myaddress",
|
|
|
|
|
"addresses", "my.addresses", "myaddresses");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -111,4 +116,5 @@ class SanitizerTests {
|
|
|
|
|
assertThat(sanitizer.sanitize("verylOCkish", "secret")).isEqualTo("******");
|
|
|
|
|
assertThat(sanitizer.sanitize("veryokish", "secret")).isEqualTo("secret");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|