Skip to content

Commit

Permalink
fix #483
Browse files Browse the repository at this point in the history
  • Loading branch information
shimono committed Oct 23, 2019
1 parent f803bad commit 51c1cba
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/io/personium/core/PersoniumCoreException.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ 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");
/**
* Range header specification error.
*/
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/io/personium/core/rs/box/NullResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ 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 @@ -130,6 +131,16 @@ 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 @@ -281,12 +292,21 @@ public Object nextPath(@PathParam("nextPath") final String nextPath,
* @return Jax-RS response object
*/
@DELETE
public final Response delete() {
public final Response delete(@HeaderParam(HttpHeaders.IF_MATCH) final String ifMatch) {
//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
2 changes: 2 additions & 0 deletions src/main/resources/personium-messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ 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.


# PR416-DV
io.personium.core.msg.PR416-DV-0001=Requested range not satisfiable.
Expand Down
105 changes: 105 additions & 0 deletions src/test/java/io/personium/core/rs/box/NullResourceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Personium
* Copyright 2017-2019 Personium Project
* - FUJITSU LIMITED
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.personium.core.rs.box;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import io.personium.core.PersoniumCoreException;
import io.personium.core.model.Cell;
import io.personium.core.model.DavCmp;
import io.personium.core.model.DavRsCmp;
import io.personium.test.categories.Unit;

/**
* ODataSvcCollectionResource unit test classs.
*/
@Category({ Unit.class })
public class NullResourceTest {

/** Target class of unit test. */
private NullResource nullResource;

@Before
public void before() {
// --------------------
// Test method args
// --------------------
String url = "https://personium/cell/box";
String name = "col";
String cellUrl = "https://personium/cell/";

// --------------------
// Mock settings
// --------------------
DavRsCmp davRsCmp = mock(DavRsCmp.class);
DavCmp davCmp = mock(DavCmp.class);
Cell cell = mock(Cell.class);
doReturn(null).when(davRsCmp).getAccessContext();
doReturn(url).when(davRsCmp).getUrl();
doReturn(cell).when(davRsCmp).getCell();
doReturn(cellUrl).when(cell).getUrl();
doReturn(name).when(davCmp).getName();
nullResource = new NullResource(davRsCmp, davCmp, false);

}

/**
*
*/
@Test
public void put_With_IfMatchWildCard_ShouldReturn_412() {
try {
nullResource.put("text/html", "*", null);
fail();
}catch (PersoniumCoreException e) {
assertEquals(PersoniumCoreException.Dav.NO_ENTITY_MATCH.getCode(), e.getCode());
}
}

/**
* delete_ShouldReturn_404
*/
@Test
public void delete_ShouldReturn_404() {
try {
nullResource.delete(null);
fail();
}catch (PersoniumCoreException e) {
assertEquals(PersoniumCoreException.Dav.RESOURCE_NOT_FOUND.getCode(), e.getCode());
}
}
/**
* delete_With_IfMatchWildCard_ShouldReturn_412
*/
@Test
public void delete_With_IfMatchWildCard_ShouldReturn_412() {
try {
nullResource.delete("*");
fail();
}catch (PersoniumCoreException e) {
assertEquals(PersoniumCoreException.Dav.NO_ENTITY_MATCH.getCode(), e.getCode());
}
}
}

0 comments on commit 51c1cba

Please sign in to comment.