Skip to content
Snippets Groups Projects
Commit bcd35e00 authored by Evgeny Bardin's avatar Evgeny Bardin
Browse files

OZG-7092 [test] fix configuration

parent a6736c5c
Branches
No related tags found
1 merge request!1OZG-7092 Anpassung TokenChecker
......@@ -24,36 +24,49 @@
package de.ozgcloud.token;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.opensaml.xmlsec.signature.support.SignatureTrustEngine;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.annotation.DirtiesContext;
import de.ozgcloud.common.test.ITCase;
import de.ozgcloud.common.test.TestUtils;
import de.ozgcloud.token.saml.SamlTestConfiguration;
import lombok.SneakyThrows;
import net.devh.boot.grpc.client.inject.GrpcClient;
public class TokenCheckGrpcServiceITCase {
@Nested
@ITCase
@SpringBootTest(properties = {
"grpc.server.inProcessName=test",
"grpc.client.token-checker.address=in-process:test",
})
@Import(SamlTestConfiguration.class)
@DirtiesContext
class TestCheckTokenSuccessfully {
public class TokenCheckGrpcServiceITCase {
@GrpcClient("token-checker")
private TokenCheckServiceGrpc.TokenCheckServiceBlockingStub tokenCheckerStub;
@MockBean
private SignatureTrustEngine signatureTrustEngine;
@Nested
class TestCheckTokenSuccessfully {
@SneakyThrows
@BeforeEach
void init() {
when(signatureTrustEngine.validate(any(), any())).thenReturn(true);
}
@Test
void shouldAcceptToken() {
var token = TestUtils.loadTextFile("SamlResponseBayernId.xml");
......@@ -81,19 +94,10 @@ public class TokenCheckGrpcServiceITCase {
}
@Nested
@ITCase
@SpringBootTest(properties = {
"grpc.server.inProcessName=test",
"grpc.client.token-checker.address=in-process:test",
})
@DirtiesContext
class TestCheckTokenFailure {
@GrpcClient("token-checker")
private TokenCheckServiceGrpc.TokenCheckServiceBlockingStub tokenCheckerStub;
@Test
void shouldAcceptToken() {
void shouldDeclineToken() {
var token = TestUtils.loadTextFile("SamlResponseBayernId.xml");
var result = tokenCheckerStub.checkToken(buildCheckTokenRequest(token));
......
......@@ -37,9 +37,12 @@ import org.opensaml.saml.saml2.core.EncryptedAssertion;
import org.opensaml.saml.saml2.encryption.Decrypter;
import org.opensaml.xmlsec.signature.support.SignatureTrustEngine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import lombok.SneakyThrows;
@Configuration
public class SamlTestConfiguration {
public static final String POSTFACH_ID = UUID.randomUUID().toString();
......@@ -56,13 +59,14 @@ public class SamlTestConfiguration {
@SneakyThrows
@Bean
SamlTrustEngineFactory samlTrustEngineFactory() {
SignatureTrustEngine signatureTrustEngine = when(mock(SignatureTrustEngine.class).validate(any(), any())).thenReturn(true).getMock();
@Primary
SamlTrustEngineFactory samlTrustEngineFactory(SignatureTrustEngine signatureTrustEngine) {
return when(mock(SamlTrustEngineFactory.class).buildSamlTrustEngine(any())).thenReturn(signatureTrustEngine).getMock();
}
@SneakyThrows
@Bean
@Primary
SamlDecrypterFactory samlDecrypterFactory() {
var attributes = SAML_ATTRIBUTES_MAP.entrySet().stream().map(e -> initAttributeMock(e.getKey(), e.getValue())).toList();
AttributeStatement attributeStatement = when(mock(AttributeStatement.class).getAttributes()).thenReturn(attributes).getMock();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment