personium / personium-core

Core module of Personium
https://personium.io
Apache License 2.0
88 stars 16 forks source link

Unit test case ObjectIoTest.marshal_Acl failed when PathBasedCellUrl is enabled. #581

Closed tochi-y closed 4 years ago

tochi-y commented 4 years ago

Problem

Unit test case ObjectIoTest.marshal_Acl failed when PathBasedCellUrl is enabled.

[INFO] Running io.personium.core.model.jaxb.ObjectIoTest
2020-09-10 00:40:47.829 [main] [INFO ] {"@xml.base":"personium-localunit://cell.unit.example/__role/__/",
"@p.requireSchemaAuthz":"public",
"D.ace":[{"D.principal":{"D.all":"all"},
"D.grant":{"D.privilege":[{"D.read":{}}]}},
{"D.principal":{"D.href":"foo"},
"D.grant":{"D.privilege":[{"D.read":{}},
{"p.root":{}}]}}]} - ObjectIoTest
2020-09-10 00:40:47.893 [main] [INFO ] <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<acl xml:base="personium-localunit://cell.unit.example/__role/__/" p:requireSchemaAuthz="public" xmlns:p="urn:x-personium:xmlns" xmlns="DAV:">
<ace>
<principal>
<all>all</all>
</principal>
<grant>
<privilege>
<D:read xmlns:D="DAV:"/>
</privilege>
</grant>
</ace>
<ace>
<principal>
<href>foo</href>
</principal>
<grant>
<privilege>
<D:read xmlns:D="DAV:"/>
</privilege>
<privilege>
<p:root/>
</privilege>
</grant>
</ace>
</acl> - ObjectIoTest
2020-09-10 00:40:47.915 [main] [INFO ] //acl[position()=1]/@base = personium-localunit://cell.unit.example/__role/__/ - ObjectIoTest
[ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.766 s <<< FAILURE! - in io.personium.core.model.jaxb.ObjectIoTest
[ERROR] marshal_Acl(io.personium.core.model.jaxb.ObjectIoTest)  Time elapsed: 0.757 s  <<< FAILURE!
org.junit.ComparisonFailure: expected:<[https]://cell.unit.example...> but was:<[personium-localunit]://cell.unit.example...>
    at io.personium.core.model.jaxb.ObjectIoTest.marshal_Acl(ObjectIoTest.java:126)

If PathBasedCellUrl is disabled, the test case succeeds.

Cause

When ACL.setBase method is called, the base value to set is variant depending on the PathBasedCellUrl value.

https://github.com/personium/personium-core/blob/56882d7b16c2a7a43126e22df2b3c0b671592523/src/test/java/io/personium/core/model/jaxb/ObjectIoTest.java#L84 https://github.com/personium/personium-core/blob/56882d7b16c2a7a43126e22df2b3c0b671592523/src/main/java/io/personium/core/model/jaxb/Acl.java#L97 https://github.com/personium/personium-core/blob/56882d7b16c2a7a43126e22df2b3c0b671592523/src/main/java/io/personium/core/utils/UriUtils.java#L189

And the default PathBasedCellUrl value is false. https://github.com/personium/personium-core/blob/56882d7b16c2a7a43126e22df2b3c0b671592523/src/main/resources/personium-unit-config-default.properties#L39

tochi-y commented 4 years ago

ObjectIoTest.marshal_Acl is currently run with no configuration of ''PathBasedCellUrl" and "FQDN". So their values are default value if personium-unit-config-properties is not placed. In the default values case, this line assigned https:/.

https://github.com/personium/personium-core/blob/56882d7b16c2a7a43126e22df2b3c0b671592523/src/main/java/io/personium/core/utils/UriUtils.java#L188

So the results are different by PathBasedCellUrl value.

PathBasedCellUrl true -> https://cell.unit.example/__role/__/

https://github.com/personium/personium-core/blob/56882d7b16c2a7a43126e22df2b3c0b671592523/src/main/java/io/personium/core/utils/UriUtils.java#L193

PathBasedCellUrl false -> personium-localunit://cell.unit.example/__role/__/

https://github.com/personium/personium-core/blob/56882d7b16c2a7a43126e22df2b3c0b671592523/src/main/java/io/personium/core/utils/UriUtils.java#L203