-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Throyer/development
swagger authentication improve
- Loading branch information
Showing
11 changed files
with
107 additions
and
36 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
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
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
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
45 changes: 45 additions & 0 deletions
45
src/test/java/com/github/throyer/common/springboot/swagger/SwaggerAuthTests.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,45 @@ | ||
package com.github.throyer.common.springboot.swagger; | ||
|
||
import static org.springframework.http.HttpHeaders.AUTHORIZATION; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
@SpringBootTest(webEnvironment = WebEnvironment.MOCK) | ||
@AutoConfigureMockMvc | ||
@TestPropertySource(properties = { | ||
"SWAGGER_USERNAME=test", | ||
"SWAGGER_PASSWORD=test"}) | ||
public class SwaggerAuthTests { | ||
|
||
@Autowired | ||
private MockMvc api; | ||
|
||
@Test | ||
@DisplayName("Deve exibir a documentação com basic auth valido") | ||
public void should_display_the_swagger_docs_ui_with_valid_credentials() throws Exception { | ||
|
||
var request = get("/swagger-ui/index.html?configUrl=/documentation/schemas/swagger-config") | ||
.header(AUTHORIZATION, "Basic dGVzdDp0ZXN0"); | ||
|
||
api.perform(request) | ||
.andExpect(status().isOk()); | ||
} | ||
@Test | ||
@DisplayName("Não deve exibir a documentação com basic auth invalido") | ||
public void must_not_display_the_swagger_docs_ui_with_invalid_credentials() throws Exception { | ||
var request = get("/swagger-ui/index.html?configUrl=/documentation/schemas/swagger-config") | ||
.header(AUTHORIZATION, "Basic anViaWxldTppcmluZXU="); | ||
|
||
api.perform(request) | ||
.andExpect(status().isUnauthorized()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...royer/common/springboot/SwaggerTests.java → ...mmon/springboot/swagger/SwaggerTests.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
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