Skip to content

Commit

Permalink
add test for pathTraversal
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Aug 6, 2024
1 parent 765a4ef commit 0cb4f8e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import commercetools.discount_code.DiscountCodeFixtures;
import commercetools.utils.CommercetoolsTestUtils;

import io.vrap.rmf.base.client.error.NotFoundException;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -151,6 +153,16 @@ public void expandDiscountCodeReference() {
});
}

@Test
public void pathTraversal() {
CartsFixtures.withCart(cart -> {
NotFoundException e = org.junit.jupiter.api.Assertions.assertThrows(NotFoundException.class, () -> {
CommercetoolsTestUtils.getProjectApiRoot().carts().withId("../categories").get().executeBlocking();
});
Assertions.assertThat(e.getMessage()).contains("..%2Fcategories");
});
}

private void withUpdateableCartAndDiscount(final BiFunction<Cart, DiscountCode, Cart> function) {
DiscountCodeFixtures
.withUpdateableDiscountCode(discountCodeDraftBuilder -> discountCodeDraftBuilder.isActive(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

package com.commercetools;

import com.commercetools.api.client.ProjectApiRoot;
import com.commercetools.api.defaultconfig.ApiRootBuilder;

import io.vrap.rmf.base.client.ApiHttpRequest;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class EncodePathParamTest {
@Test
public void testPathTraversal() {
final ProjectApiRoot project = ApiRootBuilder.of().withApiBaseUrl("").build("test");

final ApiHttpRequest httpRequest = project.carts().withId("../categories").get().createHttpRequest();
Assertions.assertThat(httpRequest.getUri().toString()).isEqualTo("test/carts/..%2Fcategories");
}

}

0 comments on commit 0cb4f8e

Please sign in to comment.