Skip to content

Commit

Permalink
Revert "Fix #483 #484 If-Match when resource does not exists and If-N…
Browse files Browse the repository at this point in the history
…one-Match when it exists."
  • Loading branch information
tochi-y authored Nov 5, 2019
1 parent 38589e4 commit cfbf85e
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 220 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.19</version>
<version>1.18</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/io/personium/core/PersoniumCoreException.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,6 @@ public static class Dav {
* When "F" is specified in the Overwrite header but the resource of the destination already exists.
*/
public static final PersoniumCoreException DESTINATION_ALREADY_EXISTS = create("PR412-DV-0002");
/**
* No Entity is matching.
*/
public static final PersoniumCoreException NO_ENTITY_MATCH = create("PR412-DV-0003");
/**
* The Etag of the corresponding resource match.
*/
public static final PersoniumCoreException ETAG_MATCH = create("PR412-DV-0004");
/**
* Range header specification error.
*/
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/io/personium/core/rs/box/DavFileResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ public DavFileResource(final DavRsCmp parent, final DavCmp davCmp) {
@PUT
public Response put(@HeaderParam(HttpHeaders.CONTENT_TYPE) final String contentType,
@HeaderParam(HttpHeaders.IF_MATCH) final String ifMatch,
@HeaderParam(HttpHeaders.IF_NONE_MATCH) final String ifNoneMatch,
final InputStream inputStream) {
if ("*".equals(ifNoneMatch)) {
throw PersoniumCoreException.Dav.ETAG_MATCH;
}
// Access Control
this.davRsCmp.checkAccessContext(BoxPrivilege.WRITE_CONTENT);

Expand Down
22 changes: 1 addition & 21 deletions src/main/java/io/personium/core/rs/box/NullResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public final Response get() {
@PUT
public final Response put(
@HeaderParam(HttpHeaders.CONTENT_TYPE) final String contentType,
@HeaderParam(HttpHeaders.IF_MATCH) final String ifMatch,
final InputStream inputStream) {

//Access control
Expand All @@ -131,16 +130,6 @@ public final Response put(
throw PersoniumCoreException.Dav.HAS_NOT_PARENT.params(this.davRsCmp.getParent().getUrl());
}

// If If-Match: * is specified, then should return 412
// https://tools.ietf.org/html/rfc7232#section-3.1
// If the field-value is "*", the condition is false
// if the origin server does not have a current representation
// for the target resource.
// Interpretation: if any value is specified then should evaluated as false
if (ifMatch != null) {
throw PersoniumCoreException.Dav.NO_ENTITY_MATCH;
}

Response response = this.davRsCmp.getDavCmp().putForCreate(contentType, inputStream).build();

// post event to EventBus
Expand Down Expand Up @@ -292,21 +281,12 @@ public Object nextPath(@PathParam("nextPath") final String nextPath,
* @return Jax-RS response object
*/
@DELETE
public final Response delete(@HeaderParam(HttpHeaders.IF_MATCH) final String ifMatch) {
public final Response delete() {
//Access control
if (!this.isParentNull) {
this.davRsCmp.getParent().checkAccessContext(BoxPrivilege.UNBIND);
}

// If If-Match: * is specified, then should return 412
// https://tools.ietf.org/html/rfc7232#section-3.1
// If the field-value is "*", the condition is false
// if the origin server does not have a current representation
// for the target resource.
if (ifMatch != null) {
throw PersoniumCoreException.Dav.NO_ENTITY_MATCH;
}

throw PersoniumCoreException.Dav.RESOURCE_NOT_FOUND.params(this.davRsCmp.getUrl());
}

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/io/personium/core/utils/HttpClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public class HttpClientFactory {
/** Connection timeout value.*/
private static final int TIMEOUT = 60000; // 20000;

/** Addr local. */
public static final String IP_ADDR_LOCAL = "127.0.0.1";

/** Constructor. */
private HttpClientFactory() {
}
Expand Down Expand Up @@ -103,7 +100,7 @@ private static CloseableHttpClient createAlwaysLocal(RequestConfig config) {
@Override
public InetAddress[] resolve(final String host) throws UnknownHostException {
// Always 127.0.0.1
return new InetAddress[] { InetAddress.getByName(IP_ADDR_LOCAL) };
return new InetAddress[] { InetAddress.getByName("127.0.0.1") };
}
};
HttpClientConnectionManager cm = new BasicHttpClientConnectionManager(registry,
Expand Down
5 changes: 1 addition & 4 deletions src/main/resources/personium-messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ io.personium.core.msg.PR400-DV-0002=XML content error.
io.personium.core.msg.PR400-DV-0003=Invalid depth header value:[{0}].
io.personium.core.msg.PR400-DV-0004=Role not found.
io.personium.core.msg.PR400-DV-0005=Box not found url:[{0}].
io.personium.core.msg.PR400-DV-0006=XML validation error. Cause:[{0}].
io.personium.core.msg.PR400-DV-0006=XML validate error. Cause:[{0}].
io.personium.core.msg.PR400-DV-0007=Cannot add any more child resources.
io.personium.core.msg.PR400-DV-0008=Hierarchy of the collection is too deep.
io.personium.core.msg.PR400-DV-0009=Request header {0} value is invalid [{1}].
Expand Down Expand Up @@ -135,9 +135,6 @@ io.personium.core.msg.PR409-DV-0002=File [{0}] already exists.
# PR412-DV
io.personium.core.msg.PR412-DV-0001=ETag does not match.
io.personium.core.msg.PR412-DV-0002=Overwrite header is "F" and the destination URL is already mapped to a resource.
io.personium.core.msg.PR412-DV-0003=No entity matching.
io.personium.core.msg.PR412-DV-0004=An entity matches with the given ETag.


# PR416-DV
io.personium.core.msg.PR416-DV-0001=Requested range not satisfiable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import io.personium.common.utils.CommonUtils;
import io.personium.core.PersoniumCoreException;
Expand All @@ -39,6 +42,8 @@
/**
* DavCollectionResource unit test classs.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ AccessContext.class })
@Category({ Unit.class })
public class DavCollectionResourceTest {

Expand Down Expand Up @@ -111,5 +116,4 @@ public void delete_Error_recursiveHeader_is_false_davCmp_not_empty() {
assertThat(e.getCode(), is(PersoniumCoreException.Dav.HAS_CHILDREN.getCode()));
}
}

}
62 changes: 0 additions & 62 deletions src/test/java/io/personium/core/rs/box/DavFileResourceTest.java

This file was deleted.

105 changes: 0 additions & 105 deletions src/test/java/io/personium/core/rs/box/NullResourceTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Personium
* Copyright 2014-2019 Personium Project
* - FUJITSU LIMITED
* personium.io
* Copyright 2014 FUJITSU LIMITED
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,7 +54,7 @@ public class UserDataDeleteTest extends AbstractUserDataTest {
String userDataId = "userdata001";

/**
* Constructor.
* コンストラクタ.
*/
public UserDataDeleteTest() {
super(new PersoniumCoreApplication());
Expand Down Expand Up @@ -116,7 +115,7 @@ public UserDataDeleteTest() {

// DELETEを実行
deleteUserData(cellName, boxName, "colhoge", entityTypeName,
userDataId, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_PRECONDITION_FAILED);
userDataId, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_NOT_FOUND);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Personium
* Copyright 2014-2019 Personium Project
* - FUJITSU LIMITED
* personium.io
* Copyright 2014 FUJITSU LIMITED
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,7 +48,7 @@ public class AssociationEndDeleteTest extends AbstractCase {
private static final String ENTITY_TYPE_NAME = "Product";

/**
* Constructor.
* コンストラクタ.
*/
public AssociationEndDeleteTest() {
super(new PersoniumCoreApplication());
Expand Down Expand Up @@ -148,7 +147,7 @@ public AssociationEndDeleteTest() {
.with("entityTypeName", ENTITY_TYPE_NAME)
.with("ifMatch", "*")
.returns()
.statusCode(HttpStatus.SC_PRECONDITION_FAILED)
.statusCode(HttpStatus.SC_NOT_FOUND)
.debug();

// レスポンスヘッダーのチェック
Expand Down

0 comments on commit cfbf85e

Please sign in to comment.