Skip to content

Commit 2df5dfc

Browse files
committed
added 401 and 403 to expected UpnpReponsed issue #232
1 parent a23f860 commit 2df5dfc

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

yaacc/src/main/java/org/fourthline/cling/model/message/UpnpResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public static enum Status {
2626

2727
OK(200, "OK"),
2828
BAD_REQUEST(400, "Bad Request"),
29+
UNAUTHORIZED(401, "Unauthorized"),
30+
FORBIDDEN(403, "Forbidden"),
2931
NOT_FOUND(404, "Not Found"),
3032
METHOD_NOT_SUPPORTED(405, "Method Not Supported"),
3133
PRECONDITION_FAILED(412, "Precondition Failed"),

yaacc/src/test/java/de/yaacc/upnp/server/http/HttpRequestSenderTest.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
*/
1919
package de.yaacc.upnp.server.http;
2020

21+
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertFalse;
23+
import static org.junit.Assert.assertNotNull;
24+
import static org.junit.Assert.assertTrue;
25+
2126
import org.apache.hc.core5.http.ContentType;
2227
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
2328
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
@@ -26,11 +31,6 @@
2631

2732
import java.nio.charset.StandardCharsets;
2833

29-
import static org.junit.Assert.assertEquals;
30-
import static org.junit.Assert.assertFalse;
31-
import static org.junit.Assert.assertNotNull;
32-
import static org.junit.Assert.assertTrue;
33-
3434
public class HttpRequestSenderTest {
3535

3636
@Test
@@ -70,11 +70,25 @@ public void testCreateResponse_401_doesNotThrow() throws Exception {
7070
StreamResponseMessage msg = new HttpRequestSender().createResponse(buildResponse(401, "Unauthorized"));
7171
assertNotNull(msg);
7272
assertEquals(401, msg.getOperation().getStatusCode());
73-
assertEquals("HTTP 401", msg.getOperation().getStatusMessage());
73+
assertEquals("Unauthorized", msg.getOperation().getStatusMessage());
7474
assertTrue("401 must report isFailed() so the discovery loop skips the device",
7575
msg.getOperation().isFailed());
7676
}
7777

78+
/**
79+
* Regression for issue #232. A 403 produce a synthetic failed
80+
* UpnpResponse so the caller can skip the device.
81+
*/
82+
@Test
83+
public void testCreateResponse_403_doesNotThrow() throws Exception {
84+
StreamResponseMessage msg = new HttpRequestSender().createResponse(buildResponse(403, "Forbidden"));
85+
assertNotNull(msg);
86+
assertEquals(403, msg.getOperation().getStatusCode());
87+
assertEquals("Forbidden", msg.getOperation().getStatusMessage());
88+
assertTrue("403 must report isFailed() so the discovery loop skips the device",
89+
msg.getOperation().isFailed());
90+
}
91+
7892
/**
7993
* Regression for issue #219 / PR #221. 503 was added to the canonical
8094
* Status enum in that PR; verify it still maps to the canonical

0 commit comments

Comments
 (0)