Skip to content

Commit fe8f8fd

Browse files
committed
fix #762 - throw ForbiddenUserException when 403 is returned and it's not a content version required
1 parent 354dd91 commit fe8f8fd

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/main/java/com/marklogic/client/impl/OkHttpServices.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,10 +1471,6 @@ private TemporalDescriptor putPostDocumentImpl(RequestLogger reqlog, String meth
14711471
throw new FailedRequestException(
14721472
"Content version required to write document", failure);
14731473
}
1474-
throw new FailedRequestException(
1475-
"Precondition required to write document", failure);
1476-
} else if (status == STATUS_FORBIDDEN) {
1477-
FailedRequest failure = extractErrorFields(response);
14781474
throw new ForbiddenUserException(
14791475
"User is not allowed to write documents", failure);
14801476
}
@@ -3878,8 +3874,6 @@ private Request.Builder addTransactionScopedCookies(Request.Builder requestBldr,
38783874
if ( cookie.getMaxAge() == 0 ) {
38793875
continue;
38803876
}
3881-
// TODO: eval if we need handling for MIN_VALUE
3882-
// else if ( cookie.getMaxAge() == Integer.MIN_VALUE ) {
38833877
// don't forward the cookie if it has a max age and we're past the max age
38843878
if ( cookie.getMaxAge() > 0 ) {
38853879
Calendar expiration = (Calendar) ((TransactionImpl) transaction).getCreatedTimestamp().clone();

src/test/java/com/marklogic/client/test/InvalidUserTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.marklogic.client.ForbiddenUserException;
2929
import com.marklogic.client.DatabaseClientFactory.Authentication;
3030
import com.marklogic.client.document.TextDocumentManager;
31+
import com.marklogic.client.io.DocumentMetadataHandle;
3132
import com.marklogic.client.io.StringHandle;
3233

3334
public class InvalidUserTest {
@@ -76,6 +77,17 @@ public void test_issue_762() {
7677
assertNotNull("Error Message is null", message);
7778
assertTrue("Error Message", message.equals("SEC-PRIV"));
7879
assertTrue("Status code", (statusCode == 403));
80+
try {
81+
DocumentMetadataHandle metadata = new DocumentMetadataHandle().withQuality(3);
82+
readOnlyClient.newDocumentManager().writeAs("test.txt", metadata, "test");
83+
fail("reader could write a document with metadata, but shouldn't be able to");
84+
} catch (ForbiddenUserException e2) {
85+
message = e2.getFailedRequest().getMessageCode();
86+
statusCode = e2.getFailedRequest().getStatusCode();
87+
assertNotNull("Error Message is null", message);
88+
assertTrue("Error Message", message.equals("SEC-PRIV"));
89+
assertTrue("Status code", (statusCode == 403));
90+
}
7991
} finally {
8092
readOnlyClient.release();
8193
}

0 commit comments

Comments
 (0)