-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support DwC - Avoid superflous WARN log messages (#1415)
* Avoid warn messages in case there is no service configuration * fix fragile test * make the class fields more restrictive Signed-off-by: liga-oz <[email protected]> --------- Signed-off-by: liga-oz <[email protected]> Co-authored-by: liga-oz <[email protected]>
- Loading branch information
Showing
3 changed files
with
72 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
java-security/src/test/java/com/sap/cloud/security/servlet/HybridTokenFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.sap.cloud.security.servlet; | ||
|
||
import ch.qos.logback.core.read.ListAppender; | ||
import com.sap.cloud.security.token.XsuaaToken; | ||
import org.apache.commons.io.IOUtils; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.LoggerFactory; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.classic.Logger; | ||
|
||
import java.io.IOException; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class HybridTokenFactoryTest { | ||
|
||
private ListAppender<ILoggingEvent> logWatcher; | ||
private HybridTokenFactory cut; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
cut = new HybridTokenFactory(); | ||
cut.xsAppId = null; | ||
cut.xsScopeConverter = null; | ||
logWatcher = new ListAppender<>(); | ||
logWatcher.start(); | ||
((Logger) LoggerFactory.getLogger(HybridTokenFactory.class)).addAppender(logWatcher); | ||
} | ||
|
||
@AfterEach | ||
void teardown() { | ||
((Logger) LoggerFactory.getLogger(HybridTokenFactory.class)).detachAndStopAllAppenders(); | ||
} | ||
|
||
@Test | ||
void oneWarningMessageIncaseSecurityConfigIsMissing() throws IOException { | ||
String jwt = IOUtils.resourceToString("/xsuaaJwtBearerTokenRSA256.txt", UTF_8); | ||
XsuaaToken token = (XsuaaToken) cut.create(jwt); | ||
cut.create(jwt); | ||
|
||
assertThat(token.getIssuer()).isEqualTo("http://auth.com"); | ||
assertThrows(IllegalArgumentException.class, () -> token.hasLocalScope("abc")); | ||
assertThat(logWatcher.list).isNotNull().hasSize(1); | ||
assertThat(logWatcher.list.get(0).getMessage()).contains("There is no xsuaa service configuration"); | ||
} | ||
} |