Skip Preauthorise annotation for Pact test

Viewed 129

Doing PACT testing for application having microservices architecture and test case is failing due to authentication. Either some way to skip authorisation or i'm not able to find where should i give authorisation at provider side. I tried with @EnableMethodsecurity also it didn't work I want some way to apply authorisation in provider or how can i skip it i tried with @WithMockUser that also didn't work for me. PactTest Class

@Provider("test_provider")
@PactFolder("../document-management/target/pacts")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = "/application-test.properties")
@Import(TestBeanConfiguration.class)
public class DocumentDataPactProviderTest {

    @TestTarget
    public final Target target = new SpringBootHttpTarget();

    @MockBean
    private DocumentDataService documentDataService;

    @Autowired
    private ApplicationProperties applicationProperties;

    @State("DocData 1 exists")
    public void DocData1Exists() {
        initDocumentService();
    }

    private void initDocumentService() {
        final DocumentData documentData = new DocumentData();
        documentData.setDocId("1");
        documentData.setDocName("kost");
        documentData.setDocLocation("Armenia");
        when(documentDataService.findDocument("1")).thenReturn(documentData);
    }  ```
Test Configuration class
``` @TestConfiguration
public class TestBeanConfiguration {

    @Bean
    public SimpleMessageListenerContainer simpleMessageListenerContainer(AmazonSQSAsync amazonSQSAsync) {
        SimpleMessageListenerContainerFactory factory = new SimpleMessageListenerContainerFactory();
        factory.setAutoStartup(false);
        factory.setAmazonSqs(amazonSQSAsync);
        SimpleMessageListenerContainer simpleMessageListenerContainer = factory.createSimpleMessageListenerContainer();
        simpleMessageListenerContainer.setMessageHandler(messageHandler());
        return simpleMessageListenerContainer;
    }

    @Bean(name = "amazonSQSAsync")
    public AmazonSQSAsync amazonSQSAsync() {
        return mock(AmazonSQSAsync.class);
    }

    @Bean(name = "messageHandler")
    public QueueMessageHandler messageHandler() {
        return mock(QueueMessageHandler.class);
    }

    @Bean
    public WebSecurityConfigurer<WebSecurity> webSecurityConfigurer() {
        return new WebSecurityConfigurer<>() {
            @Override
            public void init(WebSecurity webSecurity) {

            }

            @Override
            public void configure(WebSecurity webSecurity) {
                webSecurity.ignoring().antMatchers("/**");
            }
        };
    } ```





0 Answers
Related