use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider in project dataverse by IQSS.
the class JsonParserTest method testIpGroupRoundTrip.
@Test
public void testIpGroupRoundTrip() {
IpGroup original = new IpGroup();
original.setDescription("Ip group description");
original.setDisplayName("Test-ip-group");
original.setId(42l);
original.setPersistedGroupAlias("test-ip-group");
original.setGroupProvider(new IpGroupProvider(null));
original.add(IpAddressRange.make(IpAddress.valueOf("1.2.1.1"), IpAddress.valueOf("1.2.1.10")));
original.add(IpAddressRange.make(IpAddress.valueOf("1.1.1.1"), IpAddress.valueOf("1.1.1.1")));
original.add(IpAddressRange.make(IpAddress.valueOf("1:2:3::4:5"), IpAddress.valueOf("1:2:3::4:5")));
original.add(IpAddressRange.make(IpAddress.valueOf("1:2:3::3:ff"), IpAddress.valueOf("1:2:3::3:5")));
JsonObject serialized = JsonPrinter.json(original).build();
System.out.println(serialized.toString());
IpGroup parsed = new JsonParser().parseIpGroup(serialized);
assertEquals(original, parsed);
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider in project dataverse by IQSS.
the class JsonParserTest method testIpGroupRoundTrip_singleIpv6Address.
@Test
public void testIpGroupRoundTrip_singleIpv6Address() {
IpGroup original = new IpGroup();
original.setDescription("Ip group description");
original.setDisplayName("Test-ip-group");
original.setId(42l);
original.setPersistedGroupAlias("test-ip-group");
original.setGroupProvider(new IpGroupProvider(null));
original.add(IpAddressRange.make(IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce61"), IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce61")));
JsonObject serialized = JsonPrinter.json(original).build();
System.out.println(serialized.toString());
IpGroup parsed = new JsonParser().parseIpGroup(serialized);
assertEquals(original, parsed);
assertTrue(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce61"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce60"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce62"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0ff:fe47:ce61"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0af:fe48:ce61"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe79::22c9:d0ff:fe48:ce61"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("2.1.1.1"))));
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider in project dataverse by IQSS.
the class JsonParserTest method testIpGroupRoundTrip_singleIpv4Address.
@Test
public void testIpGroupRoundTrip_singleIpv4Address() {
IpGroup original = new IpGroup();
original.setDescription("Ip group description");
original.setDisplayName("Test-ip-group");
original.setId(42l);
original.setPersistedGroupAlias("test-ip-group");
original.setGroupProvider(new IpGroupProvider(null));
original.add(IpAddressRange.make(IpAddress.valueOf("1.1.1.1"), IpAddress.valueOf("1.1.1.1")));
JsonObject serialized = JsonPrinter.json(original).build();
System.out.println(serialized.toString());
IpGroup parsed = new JsonParser().parseIpGroup(serialized);
assertEquals(original, parsed);
assertTrue(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.1.1.1"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.1.1.2"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.1.2.1"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.1.1.0"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.1.1.250"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.2.1.1"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("2.1.1.1"))));
assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce61"))));
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider in project dataverse by IQSS.
the class ExplicitGroupTest method recursiveStructuralContainment.
@Test
public void recursiveStructuralContainment() throws GroupException {
Dataverse dvParent = makeDataverse();
ExplicitGroup parentGroup = roleAssigneeSvc.add(makeExplicitGroup(prv));
ExplicitGroup childGroup = roleAssigneeSvc.add(makeExplicitGroup(prv));
ExplicitGroup grandChildGroup = roleAssigneeSvc.add(makeExplicitGroup(prv));
parentGroup.setOwner(dvParent);
childGroup.setOwner(dvParent);
grandChildGroup.setOwner(dvParent);
childGroup.add(grandChildGroup);
parentGroup.add(childGroup);
AuthenticatedUser au = roleAssigneeSvc.add(makeAuthenticatedUser("Jane", "Doe"));
grandChildGroup.add(au);
childGroup.add(GuestUser.get());
assertTrue(grandChildGroup.structuralContains(au));
assertTrue(childGroup.structuralContains(au));
assertTrue(parentGroup.structuralContains(au));
assertTrue(childGroup.structuralContains(GuestUser.get()));
assertTrue(parentGroup.structuralContains(GuestUser.get()));
grandChildGroup.remove(au);
assertFalse(grandChildGroup.structuralContains(au));
assertFalse(childGroup.structuralContains(au));
assertFalse(parentGroup.structuralContains(au));
childGroup.add(AuthenticatedUsers.get());
assertFalse(grandChildGroup.structuralContains(au));
assertFalse(childGroup.structuralContains(au));
assertFalse(parentGroup.structuralContains(au));
assertTrue(childGroup.structuralContains(AuthenticatedUsers.get()));
final IpGroup ipGroup = new IpGroup(new IpGroupProvider(null));
grandChildGroup.add(ipGroup);
ipGroup.add(IpAddressRange.make(IpAddress.valueOf("0.0.1.1"), IpAddress.valueOf("0.0.255.255")));
assertTrue(grandChildGroup.structuralContains(ipGroup));
assertTrue(childGroup.structuralContains(ipGroup));
assertTrue(parentGroup.structuralContains(ipGroup));
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider in project dataverse by IQSS.
the class ExplicitGroupTest method recursiveLogicalContainment.
@Test
public void recursiveLogicalContainment() throws GroupException {
Dataverse dvParent = makeDataverse();
ExplicitGroup parentGroup = roleAssigneeSvc.add(makeExplicitGroup("parent", prv));
ExplicitGroup childGroup = roleAssigneeSvc.add(makeExplicitGroup("child", prv));
ExplicitGroup grandChildGroup = roleAssigneeSvc.add(makeExplicitGroup("grandChild", prv));
parentGroup.setOwner(dvParent);
childGroup.setOwner(dvParent);
grandChildGroup.setOwner(dvParent);
childGroup.add(grandChildGroup);
parentGroup.add(childGroup);
AuthenticatedUser au = roleAssigneeSvc.add(makeAuthenticatedUser("Jane", "Doe"));
grandChildGroup.add(au);
childGroup.add(GuestUser.get());
DataverseRequest auReq = makeRequest(au);
DataverseRequest guestReq = makeRequest();
assertTrue(grandChildGroup.contains(auReq));
assertTrue(childGroup.contains(auReq));
assertTrue(parentGroup.contains(auReq));
assertTrue(childGroup.contains(guestReq));
assertTrue(parentGroup.contains(guestReq));
grandChildGroup.remove(au);
assertFalse(grandChildGroup.contains(auReq));
assertFalse(childGroup.contains(auReq));
assertFalse(parentGroup.contains(auReq));
childGroup.add(AuthenticatedUsers.get());
assertFalse(grandChildGroup.contains(auReq));
assertTrue(childGroup.contains(auReq));
assertTrue(parentGroup.contains(auReq));
final IpGroup ipGroup = roleAssigneeSvc.add(new IpGroup(new IpGroupProvider(null)));
grandChildGroup.add(ipGroup);
ipGroup.add(IpAddressRange.make(IpAddress.valueOf("0.0.1.1"), IpAddress.valueOf("0.0.255.255")));
final IpAddress ip = IpAddress.valueOf("0.0.128.128");
final DataverseRequest request = new DataverseRequest(GuestUser.get(), ip);
assertTrue(ipGroup.contains(request));
assertTrue(grandChildGroup.contains(request));
assertTrue(parentGroup.contains(request));
childGroup.add(GuestUser.get());
assertTrue(childGroup.contains(guestReq));
assertTrue(parentGroup.contains(guestReq));
assertFalse(grandChildGroup.contains(guestReq));
}
Aggregations