Skip to content

Commit c405912

Browse files
committed
GH-5220 Add test: follow redirect on transaction DELETE (clear)
1 parent 1c6fa20 commit c405912

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

core/http/client/src/test/java/org/eclipse/rdf4j/http/client/RDF4JProtocolSessionTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import static org.mockserver.model.HttpRequest.request;
1515
import static org.mockserver.model.HttpResponse.response;
1616

17+
import java.io.ByteArrayInputStream;
18+
import java.nio.charset.StandardCharsets;
1719
import java.util.HashMap;
1820

1921
import org.eclipse.rdf4j.common.transaction.IsolationLevels;
@@ -128,6 +130,60 @@ public void testCreateRepositoryFollowsRedirectOnPut(MockServerClient client) th
128130
);
129131
}
130132

133+
@Test
134+
public void testRemoveDataTransactionFollowsRedirectOnDelete(MockServerClient client) throws Exception {
135+
// Start transaction and get transaction URL
136+
String transactionStartUrl = Protocol.getTransactionsLocation(getRDF4JSession().getRepositoryURL());
137+
HttpRequest transactionCreateRequest = request()
138+
.withMethod("POST")
139+
.withPath("/rdf4j-server/repositories/test/transactions");
140+
client.when(transactionCreateRequest, Times.once())
141+
.respond(response().withStatusCode(201).withHeader("Location", transactionStartUrl + "/1"));
142+
143+
// First attempt: PUT .../transactions/1?action=DELETE responds with 301 and Location header
144+
String originalPath = "/rdf4j-server/repositories/test/transactions/1";
145+
String redirectedPath = "/https/rdf4j-server/repositories/test/transactions/1";
146+
String redirectLocation = "http://localhost:" + client.getPort() + redirectedPath + "?action=DELETE";
147+
148+
client.when(
149+
request()
150+
.withMethod("PUT")
151+
.withPath(originalPath)
152+
.withQueryStringParameter("action", "DELETE"),
153+
Times.once())
154+
.respond(response().withStatusCode(301).withHeader("Location", redirectLocation));
155+
156+
// Redirect target responds successfully (204 No Content)
157+
client.when(
158+
request()
159+
.withMethod("PUT")
160+
.withPath(redirectedPath)
161+
.withQueryStringParameter("action", "DELETE"),
162+
Times.once())
163+
.respond(response().withStatusCode(204));
164+
165+
// Begin transaction, then attempt removeData (DELETE action) which should follow redirect
166+
getRDF4JSession().beginTransaction(IsolationLevels.SERIALIZABLE);
167+
ByteArrayInputStream data = new ByteArrayInputStream("<s> <p> <o> .".getBytes(StandardCharsets.UTF_8));
168+
getRDF4JSession().removeData(data, null, RDFFormat.NTRIPLES);
169+
170+
// Verify original and redirected requests occurred with header preserved
171+
client.verify(
172+
request()
173+
.withMethod("PUT")
174+
.withPath(originalPath)
175+
.withQueryStringParameter("action", "DELETE")
176+
.withHeader(testHeader, testValue)
177+
);
178+
client.verify(
179+
request()
180+
.withMethod("PUT")
181+
.withPath(redirectedPath)
182+
.withQueryStringParameter("action", "DELETE")
183+
.withHeader(testHeader, testValue)
184+
);
185+
}
186+
131187
@Test
132188
public void testUpdateRepositoryExecutesPost(MockServerClient client) throws Exception {
133189
RepositoryConfig config = new RepositoryConfig("test");

0 commit comments

Comments
 (0)