-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added redirectUrl config and functionality (#126)
* feat: added redirectUrl config and functionality Signed-off-by: jaivalis <[email protected]> * chore: fixed changelog Signed-off-by: jaivalis <[email protected]> * chore: renamed config Signed-off-by: jaivalis <[email protected]> --------- Signed-off-by: jaivalis <[email protected]>
- Loading branch information
Showing
6 changed files
with
136 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
### Artists | ||
GET {{ baseUrl }}/artists?page=0&size=10 | ||
GET {{baseUrl}}/artists?page=0&size=10 | ||
|
||
### Scrape releases | ||
PUT {{ baseUrl }}/release-scrape | ||
PUT {{baseUrl}}/release-scrape | ||
|
||
### Notify | ||
GET {{ baseUrl }}/notify-users | ||
GET {{baseUrl}}/notify-users |
13 changes: 13 additions & 0 deletions
13
release-raccoon-app/src/main/java/com/raccoon/user/RedirectConfig.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,13 @@ | ||
package com.raccoon.user; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import io.smallrye.config.ConfigMapping; | ||
|
||
@ConfigMapping(prefix = "redirect") | ||
public interface RedirectConfig { | ||
|
||
Optional<List<String>> getWhitelistedUrls(); | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,19 @@ | |
import com.raccoon.entity.repository.UserArtistRepository; | ||
import com.raccoon.entity.repository.UserRepository; | ||
import com.raccoon.search.dto.SearchResultArtistDto; | ||
import com.raccoon.user.RedirectConfig; | ||
import com.raccoon.user.UserProfileResource; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import io.quarkus.mailer.MockMailbox; | ||
import io.quarkus.test.InjectMock; | ||
import io.quarkus.test.Mock; | ||
import io.quarkus.test.TestTransaction; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
|
@@ -25,15 +29,21 @@ | |
import io.quarkus.test.security.oidc.Claim; | ||
import io.quarkus.test.security.oidc.OidcSecurity; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.Response; | ||
import io.smallrye.config.SmallRyeConfig; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
|
||
import static com.raccoon.Constants.EMAIL_CLAIM; | ||
import static io.restassured.RestAssured.given; | ||
import static org.apache.http.HttpStatus.SC_NO_CONTENT; | ||
import static org.apache.http.HttpStatus.SC_OK; | ||
import static org.apache.http.HttpStatus.SC_TEMPORARY_REDIRECT; | ||
import static org.apache.http.HttpStatus.SC_UNAUTHORIZED; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(UserProfileResource.class) | ||
|
@@ -54,6 +64,18 @@ class RaccoonUserProfileResourceIT { | |
@Inject | ||
ArtistReleaseRepository artistReleaseRepository; | ||
|
||
@Inject | ||
SmallRyeConfig smallRyeConfig; | ||
|
||
@InjectMock | ||
RedirectConfig redirectConfig; | ||
|
||
@ApplicationScoped | ||
@Mock | ||
RedirectConfig featuresConfig() { | ||
return smallRyeConfig.getConfigMapping(RedirectConfig.class); | ||
} | ||
|
||
@BeforeEach | ||
@Transactional | ||
public void setup() { | ||
|
@@ -69,11 +91,86 @@ public void setup() { | |
void getProfileOnce() { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.when().get() | ||
.when() | ||
.get() | ||
.then() | ||
.statusCode(SC_OK); | ||
|
||
assertEquals(1, mockMailbox.getMailsSentTo("[email protected]").size()); | ||
assertThat(mockMailbox.getMailsSentTo("[email protected]")) | ||
.hasSize(1); | ||
} | ||
|
||
@Test | ||
@TestSecurity(user = EXISTING_USERNAME, roles = "user") | ||
@OidcSecurity(claims = { | ||
@Claim(key = EMAIL_CLAIM, value = "[email protected]") | ||
}) | ||
@DisplayName("get should redirect when url in whitelist") | ||
void getWithRedirect_should_redirect_when_urlInWhitelist() { | ||
String redirectUrl = "https://mock.url.from.whitelist"; | ||
when(redirectConfig.getWhitelistedUrls()).thenReturn(Optional.of(List.of(redirectUrl))); | ||
|
||
Response response = given() | ||
.queryParam("redirectUrl", redirectUrl) | ||
.redirects().follow(false) | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.get() | ||
.then() | ||
.statusCode(SC_TEMPORARY_REDIRECT) | ||
.extract() | ||
.response(); | ||
|
||
assertThat(response.getHeader("Location")) | ||
.isEqualTo(redirectUrl); | ||
} | ||
|
||
@Test | ||
@TestSecurity(user = EXISTING_USERNAME, roles = "user") | ||
@OidcSecurity(claims = { | ||
@Claim(key = EMAIL_CLAIM, value = "[email protected]") | ||
}) | ||
@DisplayName("get should not redirect when url not in whitelist") | ||
void getWithRedirect_should_not_redirect_when_urlNotInWhitelist() { | ||
String redirectUrl = "https://mock.url.from.whitelist"; | ||
when(redirectConfig.getWhitelistedUrls()).thenReturn(Optional.of(List.of("not" + redirectUrl))); | ||
|
||
Response response = given() | ||
.queryParam("redirectUrl", redirectUrl) | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.get() | ||
.then() | ||
.statusCode(SC_OK) | ||
.extract() | ||
.response(); | ||
|
||
assertThat(response.getHeader("Location")) | ||
.isNull(); | ||
} | ||
|
||
@Test | ||
@TestSecurity(user = EXISTING_USERNAME, roles = "user") | ||
@OidcSecurity(claims = { | ||
@Claim(key = EMAIL_CLAIM, value = "[email protected]") | ||
}) | ||
@DisplayName("get should not redirect when url not in whitelist") | ||
void getWithRedirect_should_not_redirect_when_whitelistEmpty() { | ||
String redirectUrl = "https://mock.url.from.whitelist"; | ||
when(redirectConfig.getWhitelistedUrls()).thenReturn(Optional.empty()); | ||
|
||
Response response = given() | ||
.queryParam("redirectUrl", redirectUrl) | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.get() | ||
.then() | ||
.statusCode(SC_OK) | ||
.extract() | ||
.response(); | ||
|
||
assertThat(response.getHeader("Location")) | ||
.isNull(); | ||
} | ||
|
||
@Test | ||
|
@@ -215,7 +312,7 @@ void getUserArtists() { | |
.statusCode(SC_OK) | ||
.extract().body().jsonPath().getList("rows", ArtistDto.class); | ||
|
||
assertEquals(1, list.size()); | ||
assertThat(list).hasSize(1); | ||
assertEquals(artistDto.getName(), list.get(0).getName()); | ||
assertEquals(artistDto.getSpotifyUri(), list.get(0).getSpotifyUri()); | ||
assertEquals(artistDto.getLastfmUri(), list.get(0).getLastfmUri()); | ||
|
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