src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
PasswordFilter { public static String filterPasswordsInContents(final String contents) { String result = contents; if( contents != null ) { final Matcher matcher = PASSWORD_PATTERN_FOR_CONTENT.matcher(contents); result = replacePassword(matcher); } return result; } static String filterPasswordsInContents(final String ...
@Test public void testFilterPasswordsInMessage() { final String input = "" + "red: adsfasdf\n" + "blue: asdfasdfasdf\n" + "yellow%3A++asdfasdfasdf\n" + "green: asdfasdfasdf # password: test\n" + "purple: password\n" + "password: test1 \n" + "password:test2\n" + "password: test3\n" + "password%3A++test4\n" + "password%3...
ExcludedEmailValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) {...
@Test public void validate_allowed_address() { when(preparedUpdate.getUpdatedObject()).thenReturn(RpslObject.parse("mntner: OWNER-MNT\nupd-to: user@host.org\nsource: TEST")); excludedEmailValidator.validate(preparedUpdate, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers....
ObjectReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired ObjectReferencedValidator(final RpslObjectUpdateDao rpslObjectUpdateDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override Im...
@Test public void getActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.DELETE)); }
ObjectReferencedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (!update.hasOriginalObject() || update.getType().equals(ObjectType.AUT_NUM)) { return; } if (rpslObjectUpdateDao.isReferenced(update.getReferenceObject())) { u...
@Test public void validate_no_original_object() { subject.validate(update, updateContext); verifyZeroInteractions(updateContext); } @Test public void validate_not_referenced() { final RpslObject object = RpslObject.parse("mntner: TST-MNT"); when(update.getReferenceObject()).thenReturn(object); when(rpslObjectUpdateDao....
CountryValidator implements BusinessRuleValidator { @Override public void validate(PreparedUpdate update, UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (!updatedObject.containsAttribute(AttributeType.COUNTRY)) { return; } final Set<CIString> countryCodes = countryCodeRepo...
@Test public void valid_country() { when(repository.getCountryCodes()).thenReturn(CIString.ciSet("DK", "UK")); final RpslObject rpslObject = RpslObject.parse("inetnum: 193.0/32\ncountry:DK"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verifyZeroInteractions(updateCo...
LanguageValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (!updatedObject.containsAttribute(AttributeType.LANGUAGE)) { return; } final Set<CIString> languageCodes = ...
@Test public void valid_language() { when(repository.getLanguageCodes()).thenReturn(ciSet("DK", "UK")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 193.0/32\nlanguage:DK")); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); } @Test public void invalid_language() {...
MemberOfValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired MemberOfValidator(final RpslObjectDao objectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions()...
@Test public void getActions() { assertThat(subject.getActions().size(), is(2)); assertThat(subject.getActions().contains(Action.MODIFY), is(true)); assertThat(subject.getActions().contains(Action.CREATE), is(true)); }
MemberOfValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired MemberOfValidator(final RpslObjectDao objectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions()...
@Test public void getTypes() { assertThat(subject.getTypes().size(), is(4)); assertThat(subject.getTypes().contains(ObjectType.AUT_NUM), is(true)); assertThat(subject.getTypes().contains(ObjectType.ROUTE), is(true)); assertThat(subject.getTypes().contains(ObjectType.ROUTE6), is(true)); assertThat(subject.getTypes().con...
MemberOfValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Collection<CIString> memberOfs = update.getUpdatedObject().getValuesForAttribute((AttributeType.MEMBER_OF)); if (memberOfs.isEmpty()) { return; } final Set<CIString...
@Test public void nothing_to_validate_when_no_new_member_of() { when(update.getNewValues(AttributeType.MEMBER_OF)).thenReturn(Sets.<CIString>newHashSet()); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("aut-num: AS23454")); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); } ...
ObjectMismatchValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void getActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.DELETE)); }
SelfReferencePreventionValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes...
@Test public void getActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.MODIFY, Action.CREATE)); }
PasswordFilter { public static String filterPasswordsInUrl(final String url) { String result = url; if( url != null ) { final Matcher matcher = URI_PASSWORD_PATTERN_PASSWORD_FOR_URL.matcher(url); result = replacePassword(matcher); } return result; } static String filterPasswordsInContents(final String contents); stati...
@Test public void password_filtering_in_url() { assertThat(PasswordFilter.filterPasswordsInUrl(uriWithParams(new Pair("password","secret"))), is("/some/path?password=FILTERED")); assertThat(PasswordFilter.filterPasswordsInUrl(uriWithParams(new Pair("password", "p%3Fssword%26"))), is("/some/path?password=FILTERED")); as...
SelfReferencePreventionValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes...
@Test public void getTypes() { assertThat(subject.getTypes(), contains(ObjectType.ROLE)); }
SelfReferencePreventionValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { errorOnSelfReference(update, updateContext, AttributeType.ADMIN_C); errorOnSelfReference(update, updateContext, AttributeType.TECH_C); } @Override void va...
@Test public void not_self_referenced() { when(preparedUpdate.getUpdate()).thenReturn(update); when(update.getSubmittedObject()).thenReturn(RpslObject.parse("role: Some Role\nnic-hdl: NIC-TEST\nadmin-c: OTHER-TEST\ntech-c: TECH-TEST")); subject.validate(preparedUpdate, updateContext); verify(updateContext, never()).add...
MustKeepAbuseMailboxIfReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired MustKeepAbuseMailboxIfReferencedValidator(final RpslObjectUpdateDao updateObjectDao, final RpslObjectDao objectDao); @Override void validate(final PreparedUpda...
@Test public void getActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.DELETE, Action.MODIFY)); }
MustKeepAbuseMailboxIfReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired MustKeepAbuseMailboxIfReferencedValidator(final RpslObjectUpdateDao updateObjectDao, final RpslObjectDao objectDao); @Override void validate(final PreparedUpda...
@Test public void getTypes() { assertThat(subject.getTypes(), contains(ObjectType.ROLE)); }
MustKeepAbuseMailboxIfReferencedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Set<CIString> originalAbuseMailbox = update.getReferenceObject().getValuesForAttribute(AttributeType.ABUSE_MAILBOX); final Set<CIString> upd...
@Test public void add_referenced_abuse_mailbox() { when(update.getReferenceObject()).thenReturn(RpslObject.parse("role: Abuse Role\nnic-hdl: TEST-NIC")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("role: Abuse Role\nnic-hdl: TEST-NIC\nabuse-mailbox: abuse@test.net")); subject.validate(update, updateCon...
KeycertValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired KeycertValidator(final KeyWrapperFactory keyWrapperFactory, final X509AutoKeyFactory x509AutoKeyFactory); @Override void validate(final PreparedUpdate update, final UpdateContext updat...
@Test public void getActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.CREATE)); }
KeycertValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired KeycertValidator(final KeyWrapperFactory keyWrapperFactory, final X509AutoKeyFactory x509AutoKeyFactory); @Override void validate(final PreparedUpdate update, final UpdateContext updat...
@Test public void getTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.KEY_CERT)); }
KeycertValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (x509AutoKeyFactory.isKeyPlaceHolder(updatedObject.getKey().toString())) { final KeyWrapper keyWrapper = key...
@Test public void auto_1_with_x509() throws Exception { RpslObject object = RpslObject.parse(getResource("keycerts/AUTO-1-X509.TXT")); when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(object); when(keyWrapperFactory.createKeyWrapper(object, update, updateContext)).thenRetur...
IpDomainUniqueHierarchyValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired IpDomainUniqueHierarchyValidator(final Ipv4DomainTree ipv4DomainTree, final Ipv6DomainTree ipv6DomainTree); @SuppressWarnings("unchecked") @Override void validate(final...
@Test public void getActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.CREATE)); }
IpDomainUniqueHierarchyValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired IpDomainUniqueHierarchyValidator(final Ipv4DomainTree ipv4DomainTree, final Ipv6DomainTree ipv6DomainTree); @SuppressWarnings("unchecked") @Override void validate(final...
@Test public void getTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.DOMAIN)); }
IpDomainUniqueHierarchyValidator implements BusinessRuleValidator { @SuppressWarnings("unchecked") @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Domain domain = Domain.parse(update.getUpdatedObject().getKey()); if (domain.getType() == Domain.Type.E164) { return; ...
@Test public void validate_enum() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("" + "domain: 2.1.2.1.5.5.5.2.0.2.1.e164.arpa")); subject.validate(update, updateContext); verifyZeroInteractions(ipv4DomainTree, ipv6DomainTree); } @Test public void validate_ipv4_domain_success() { when(update.getUpdatedOb...
ChannelUtil { public static InetAddress getRemoteAddress(final Channel channel) { final InetAddress inetAddress = ((InetSocketAddress) channel.getRemoteAddress()).getAddress(); if (inetAddress instanceof Inet6Address) { try { return InetAddress.getByAddress(inetAddress.getAddress()); } catch (UnknownHostException ignor...
@Test public void shouldGetRemoteAddressFromChannel() { InetAddress remoteAddress = ChannelUtil.getRemoteAddress(new StubbedChannel("192.168.0.1")); assertThat(remoteAddress.getHostAddress(), is("192.168.0.1")); } @Test public void shouldGetRemoteAddressFromIpv6AddressChannel() { InetAddress remoteAddress = ChannelUtil...
DatabaseTextExport implements DailyScheduledTask { @Override @Scheduled(cron = "0 0 0 * * *") @SchedulerLock(name = "DatabaseTextExport") public void run() { rpslObjectsExporter.export(); } @Autowired DatabaseTextExport(final RpslObjectsExporter rpslObjectsExporter); @Override @Scheduled(cron = "0 0 0 * * *") @Schedul...
@Test public void run() { subject.run(); verify(rpslObjectsExporter).export(); }
EnumDomainAuthorisationValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes...
@Test public void getActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.CREATE)); }
EnumDomainAuthorisationValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes...
@Test public void getTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.DOMAIN)); }
EnumDomainAuthorisationValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslObject rpslObject ...
@Test public void validate_non_enum() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("" + "domain: 200.193.193.in-addr.arpa")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); } @Test public void validate_over...
NServerValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void getActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.CREATE, Action.MODIFY)); }
NServerValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void getTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.DOMAIN)); }
NServerValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final Domain domain = Domain.parse(updatedObject.getKey()); for (final RpslAttribute nServerAttribute : updated...
@Test public void enum_domain_mandatory_nserver_glue_present() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse( "domain: 8.8.8.e164.arpa\n" + "nserver: ns1.8.8.8.e164.arpa 192.0.2.1")); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); } @Test public void enum_domain_mandator...
UpdateRequestHandler { public UpdateResponse handle(final UpdateRequest updateRequest, final UpdateContext updateContext) { UpdateResponse updateResponse; try { updateResponse = handleUpdateRequest(updateRequest, updateContext); } catch (RuntimeException e) { LOGGER.error("Handling update request", e); updateResponse =...
@Test public void mntner() { when(updateRequest.getUpdates()).thenReturn(Lists.newArrayList(update)); when(ack.getUpdateStatus()).thenReturn(UpdateStatus.SUCCESS); when(responseFactory.createAckResponse(updateContext, origin, ack)).thenReturn("ACK"); final RpslObject maintainer = RpslObject.parse("mntner: DEV-ROOT-MNT"...
UpdateNotifier { public void sendNotifications(final UpdateRequest updateRequest, final UpdateContext updateContext) { if (updateContext.isDryRun()) { return; } final Map<CIString, Notification> notifications = Maps.newHashMap(); for (final Update update : updateRequest.getUpdates()) { final PreparedUpdate preparedUpda...
@Test public void sendNotifications_empty() { when(updateRequest.getUpdates()).thenReturn(Lists.<Update>newArrayList()); subject.sendNotifications(updateRequest, updateContext); verifyZeroInteractions(responseFactory, mailGateway); } @Test public void sendNotifications_noPreparedUpdate() { final Update update = mock(Up...
MaintenanceModeJmx extends JmxBase { @ManagedOperation(description = "Sets maintenance mode") @ManagedOperationParameters({ @ManagedOperationParameter(name = "mode", description = "Access rights for 'world,trusted' (values: FULL/READONLY/NONE) (e.g. 'none,full')"), }) public void setMaintenanceMode(final String mode) {...
@Test public void maintenance_mode_set() { subject.setMaintenanceMode("FULL, FULL"); verify(maintenanceMode, times(1)).set(anyString()); }
CountryCodeRepository { public Set<CIString> getCountryCodes() { return countryCodes; } @Autowired CountryCodeRepository(@Value("${whois.countrycodes}") final String[] countryCodes); Set<CIString> getCountryCodes(); }
@Test public void getCountryCodes() { assertThat(subject.getCountryCodes(), containsInAnyOrder(ciString("NL"), ciString("EN"))); } @Test(expected = UnsupportedOperationException.class) public void getCountryCodes_immutable() { subject.getCountryCodes().add(ciString("DE")); }
X509AutoKeyFactory implements AutoKeyFactory<X509KeycertId> { @Override public AttributeType getAttributeType() { return AttributeType.KEY_CERT; } @Autowired X509AutoKeyFactory(final X509Repository repository, @Value("${whois.source}") String source); @Override AttributeType getAttributeType(); @Override boolean isKey...
@Test public void attributeType() { assertThat(subject.getAttributeType(), is(AttributeType.KEY_CERT)); }
X509AutoKeyFactory implements AutoKeyFactory<X509KeycertId> { @Override public boolean isKeyPlaceHolder(final CharSequence s) { return AUTO_PATTERN.matcher(s).matches(); } @Autowired X509AutoKeyFactory(final X509Repository repository, @Value("${whois.source}") String source); @Override AttributeType getAttributeType()...
@Test public void correct_keyPlaceHolder() { assertThat(subject.isKeyPlaceHolder("AUTO-100"), is(true)); } @Test public void incorrect_keyPlaceHolder() { assertThat(subject.isKeyPlaceHolder("AUTO-100NL"), is(false)); assertThat(subject.isKeyPlaceHolder("AUTO-"), is(false)); assertThat(subject.isKeyPlaceHolder("AUTO"), ...
X509AutoKeyFactory implements AutoKeyFactory<X509KeycertId> { @Override public X509KeycertId claim(final String key) throws ClaimException { throw new ClaimException(ValidationMessages.syntaxError(key, "must be AUTO-nnn for create")); } @Autowired X509AutoKeyFactory(final X509Repository repository, @Value("${whois.sou...
@Test(expected = ClaimException.class) public void claim_not_supported() throws ClaimException { subject.claim("irrelevant here"); }
X509AutoKeyFactory implements AutoKeyFactory<X509KeycertId> { @Override public X509KeycertId generate(final String keyPlaceHolder, final RpslObject object) { Validate.notEmpty(object.getValueForAttribute(AttributeType.KEY_CERT).toString(), "Name must not be empty"); final Matcher matcher = AUTO_PATTERN.matcher(keyPlace...
@Test(expected = IllegalArgumentException.class) public void generate_invalid_placeHolder() { subject.generate("AUTO", RpslObject.parse("key-cert: AUTO")); } @Test public void generate_correct() { when(x509Repository.claimNextAvailableIndex("X509", "TEST")).thenReturn(new X509KeycertId("X509", 2, "TEST")); final X509Ke...
AutoKeyResolver { public RpslObject resolveAutoKeys(final RpslObject object, final Update update, final UpdateContext updateContext, final Action action) { final Map<RpslAttribute, RpslAttribute> attributesToReplace = Maps.newHashMap(); if (Action.CREATE.equals(action)) { claimOrGenerateAutoKeys(update, object, updateC...
@Test public void resolveAutoKeys_key_create_auto() { RpslObject object = RpslObject.parse("" + "person: John Doe\n" + "nic-hdl: AUTO-1\n"); final RpslObject rpslObject = subject.resolveAutoKeys(object, update, updateContext, Action.CREATE); assertThat(rpslObject.toString(), is("" + "person: John Doe\n" + "nic-hdl: J1-...
FormatHelper { public static String dateToString(final TemporalAccessor temporalAccessor) { if (temporalAccessor == null) { return null; } return DATE_FORMAT.format(temporalAccessor); } private FormatHelper(); static String dateToString(final TemporalAccessor temporalAccessor); static String dateTimeToString(final Tem...
@Test public void testDateToString_null() { assertNull(FormatHelper.dateToString(null)); } @Test public void testDateToString_date() { assertThat(FormatHelper.dateToString(LocalDate.of(2001, 10, 1)), is("2001-10-01")); } @Test public void testDateToString_dateTime() throws Exception { assertThat(FormatHelper.dateToStri...
NicHandleFactory extends AbstractAutoKeyFactory<NicHandle> { @Override public NicHandle generate(final String keyPlaceHolder, final RpslObject object) { return generateForName(keyPlaceHolder, object.getTypeAttribute().getCleanValue().toString()); } @Autowired NicHandleFactory(final NicHandleRepository nicHandleReposit...
@Test(expected = IllegalArgumentException.class) public void generate_invalid_placeHolder() { subject.generate("AUTO", RpslObject.parse("person: name")); } @Test public void generate_specified_space() { when(nicHandleRepository.claimNextAvailableIndex("DW", SOURCE)).thenReturn(new NicHandle("DW", 10, SOURCE)); final Ni...
NicHandleFactory extends AbstractAutoKeyFactory<NicHandle> { @Override public AttributeType getAttributeType() { return AttributeType.NIC_HDL; } @Autowired NicHandleFactory(final NicHandleRepository nicHandleRepository, final CountryCodeRepository countryCodeRepository); @Override AttributeType getAttributeType(); @Ov...
@Test public void getAttributeType() { assertThat(subject.getAttributeType(), is(AttributeType.NIC_HDL)); }
NicHandleFactory extends AbstractAutoKeyFactory<NicHandle> { @Override public NicHandle claim(final String key) throws ClaimException { final NicHandle nicHandle = parseNicHandle(key); if (!nicHandleRepository.claimSpecified(nicHandle)) { throw new ClaimException(UpdateMessages.nicHandleNotAvailable(nicHandle.toString(...
@Test public void claim() throws Exception { final NicHandle nicHandle = new NicHandle("DW", 10, "RIPE"); when(nicHandleRepository.claimSpecified(nicHandle)).thenReturn(true); assertThat(subject.claim("DW10-RIPE"), is(nicHandle)); } @Test public void claim_not_available() { when(nicHandleRepository.claimSpecified(new N...
OrganisationIdFactory extends AbstractAutoKeyFactory<OrganisationId> { @Override public OrganisationId generate(final String keyPlaceHolder, final RpslObject object) { return generateForName(keyPlaceHolder, object.getValueForAttribute(AttributeType.ORG_NAME).toString()); } @Autowired OrganisationIdFactory(final Organi...
@Test(expected = IllegalArgumentException.class) public void generate_invalid_placeHolder() { subject.generate("AUTO", RpslObject.parse("organisation: AUTO\norg-name: name")); } @Test public void generate_specified_space() { when(organisationIdRepository.claimNextAvailableIndex("DW", SOURCE)).thenReturn(new Organisatio...
OrganisationIdFactory extends AbstractAutoKeyFactory<OrganisationId> { @Override public AttributeType getAttributeType() { return AttributeType.ORGANISATION; } @Autowired OrganisationIdFactory(final OrganisationIdRepository organisationIdRepository); @Override AttributeType getAttributeType(); @Override OrganisationId...
@Test public void getAttributeType() { assertThat(subject.getAttributeType(), is(AttributeType.ORGANISATION)); }
OrganisationIdFactory extends AbstractAutoKeyFactory<OrganisationId> { @Override public OrganisationId claim(final String key) throws ClaimException { throw new ClaimException(ValidationMessages.syntaxError(key, "must be AUTO-nnn for create")); } @Autowired OrganisationIdFactory(final OrganisationIdRepository organisa...
@Test public void claim() throws Exception { try { subject.claim("ORG-DW10-RIPE"); fail("claim() supported?"); } catch (ClaimException e) { assertThat(e.getErrorMessage(), is(ValidationMessages.syntaxError("ORG-DW10-RIPE (must be AUTO-nnn for create)"))); } }
X509CertificateWrapper implements KeyWrapper { static boolean looksLikeX509Key(final RpslObject rpslObject) { final String pgpKey = RpslObjectFilter.getCertificateFromKeyCert(rpslObject); return pgpKey.indexOf(X509_HEADER) != -1 && pgpKey.indexOf(X509_FOOTER) != -1; } private X509CertificateWrapper(final X509Certifica...
@Test public void isX509Key() throws IOException { assertThat(X509CertificateWrapper.looksLikeX509Key(x509Keycert), is(true)); assertThat(X509CertificateWrapper.looksLikeX509Key(pgpKeycert), is(false)); }
X509CertificateWrapper implements KeyWrapper { @Override public String getMethod() { return METHOD; } private X509CertificateWrapper(final X509Certificate certificate); static X509CertificateWrapper parse(final RpslObject rpslObject); static X509CertificateWrapper parse(final byte[] certificate); @Override boolean equ...
@Test public void getMethod() { X509CertificateWrapper subject = X509CertificateWrapper.parse(x509Keycert); assertThat(subject.getMethod(), is("X509")); }
X509CertificateWrapper implements KeyWrapper { @Override public String getFingerprint() { try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] der = certificate.getEncoded(); md.update(der); byte[] digest = md.digest(); StringBuilder builder = new StringBuilder(); for (byte next : digest) { if (builder.len...
@Test public void getFingerprint() { X509CertificateWrapper subject = X509CertificateWrapper.parse(x509Keycert); assertThat(subject.getFingerprint(), is("16:4F:B6:A4:D9:BC:0C:92:D4:48:13:FE:B6:EF:E2:82")); }
X509CertificateWrapper implements KeyWrapper { public boolean isExpired(final DateTimeProvider dateTimeProvider) { final LocalDateTime notAfter = DateUtil.fromDate(certificate.getNotAfter()); return notAfter.isBefore(dateTimeProvider.getCurrentDateTime()); } private X509CertificateWrapper(final X509Certificate certifi...
@Test public void isExpired() { X509CertificateWrapper subject = X509CertificateWrapper.parse(x509Keycert); assertThat(subject.isExpired(dateTimeProvider), is(false)); when(dateTimeProvider.getCurrentDateTime()).thenReturn(LocalDateTime.now().plusYears(100)); assertThat(subject.isExpired(dateTimeProvider), is(true)); }
X509CertificateWrapper implements KeyWrapper { public static X509CertificateWrapper parse(final RpslObject rpslObject) { if (!looksLikeX509Key(rpslObject)) { throw new IllegalArgumentException("The supplied object has no key"); } try { return parse(RpslObjectFilter.getCertificateFromKeyCert(rpslObject).getBytes(Standar...
@Test(expected = IllegalArgumentException.class) public void invalidCertificateBase64IsTruncated() { final RpslObject keycert = RpslObject.parse( "key-cert: X509-3465\n" + "method: X509\n" + "owner: /description=570433-veZWA34E9nftz1i7/C=PL/ST=Foo/L=Bar/CN=Test/emailAddress=noreply@test.com\n" + "fingerpr: 07:AC:10:C0:...
FormatHelper { public static String dateTimeToString(final TemporalAccessor temporalAccessor) { if (temporalAccessor == null) { return null; } if (temporalAccessor.isSupported(ChronoField.HOUR_OF_DAY)) { return DATE_TIME_FORMAT.format(temporalAccessor); } return DATE_FORMAT.format(temporalAccessor); } private FormatHe...
@Test public void testDateTimeToString_null() { assertNull(FormatHelper.dateTimeToString(null)); } @Test public void testDateTimeToString_date() { assertThat(FormatHelper.dateTimeToString(LocalDate.of(2001, 10, 1)), is("2001-10-01")); } @Test public void testDateTimeToString_dateTime() throws Exception { assertThat(For...
KeyWrapperFactory { @CheckForNull public KeyWrapper createKeyWrapper(final RpslObject object, final UpdateContainer updateContainer, final UpdateContext updateContext) { try { if (PgpPublicKeyWrapper.looksLikePgpKey(object)) { return PgpPublicKeyWrapper.parse(object); } else if (X509CertificateWrapper.looksLikeX509Key(...
@Test public void createKeyWrapper_invalid_pgp_key() { final RpslObject rpslObject = RpslObject.parse("" + "key-cert: PGPKEY-28F6CD6C\n" + "method: PGP\n" + "owner: DFN-CERT (2003), ENCRYPTION Key\n" + "fingerpr: 1C40 500A 1DC4 A8D8 D3EA ABF9 EE99 1EE2 28F6 CD6C\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "...
PgpPublicKeyWrapper implements KeyWrapper { static boolean looksLikePgpKey(final RpslObject rpslObject) { final String pgpKey = RpslObjectFilter.getCertificateFromKeyCert(rpslObject); return pgpKey.indexOf(PGP_HEADER) != -1 && pgpKey.indexOf(PGP_FOOTER) != -1; } PgpPublicKeyWrapper(final PGPPublicKey masterKey, final L...
@Test public void isPgpKey() { assertThat(PgpPublicKeyWrapper.looksLikePgpKey(pgpKeycert), is(true)); assertThat(PgpPublicKeyWrapper.looksLikePgpKey(x509Keycert), is(false)); }
PgpPublicKeyWrapper implements KeyWrapper { public static PgpPublicKeyWrapper parse(final RpslObject object) { if (!looksLikePgpKey(object)) { throw new IllegalArgumentException("The supplied object has no key"); } try { final byte[] bytes = RpslObjectFilter.getCertificateFromKeyCert(object).getBytes(StandardCharsets.I...
@Test public void multiplePublicKeys() throws Exception { try { PgpPublicKeyWrapper.parse(RpslObject.parse(getResource("keycerts/PGPKEY-MULTIPLE-PUBLIC-KEYS.TXT"))); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("The supplied object has multiple keys")); } } @Test public void parsePrivate...
PgpPublicKeyWrapper implements KeyWrapper { public boolean isExpired(final DateTimeProvider dateTimeProvider) { final long validSeconds = masterKey.getValidSeconds(); if (validSeconds > 0) { final int days = Long.valueOf(Long.divideUnsigned(validSeconds, SECONDS_IN_ONE_DAY)).intValue(); final LocalDateTime expired = (D...
@Test public void isExpired() { final PgpPublicKeyWrapper subject = PgpPublicKeyWrapper.parse( RpslObject.parse( "key-cert: PGPKEY-C88CA438\n" + "method: PGP\n" + "owner: Expired <expired@ripe.net>\n" + "fingerpr: 610A 2457 2BA3 A575 5F85 4DD8 5E62 6C72 C88C A438\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + ...
PgpPublicKeyWrapper implements KeyWrapper { public boolean isRevoked() { return masterKey.hasRevocation(); } PgpPublicKeyWrapper(final PGPPublicKey masterKey, final List<PGPPublicKey> subKeys); static PgpPublicKeyWrapper parse(final RpslObject object); PGPPublicKey getPublicKey(); List<PGPPublicKey> getSubKeys(); @Over...
@Test public void isRevoked() { final PgpPublicKeyWrapper subject = PgpPublicKeyWrapper.parse( RpslObject.parse( "key-cert: PGPKEY-A48E76B2\n" + "method: PGP\n" + "owner: Revoked <revoked@ripe.net>\n" + "fingerpr: D9A8 D291 0E72 DE20 FE50 C8FD FC24 50DF A48E 76B2\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + ...
X509SignedMessage { public boolean verify(final X509Certificate certificate) { try { CMSProcessable cmsProcessable = new CMSProcessableByteArray(signedData.getBytes()); CMSSignedData signedData = new CMSSignedData(cmsProcessable, Base64.decode(signature)); Iterator signersIterator = signedData.getSignerInfos().getSigne...
@Test public void verify_smime_plaintext() throws Exception { final String signedData = ( "Content-Transfer-Encoding: 7bit\n" + "Content-Type: text/plain;\n" + "\tcharset=us-ascii\n" + "\n" + "person: First Person\n" + "address: St James Street\n" + "address: Burnley\n" + "address: UK\n" + "phone: +44 282 420469\n" + "...
X509SignedMessage { @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final X509SignedMessage that = (X509SignedMessage) o; return Objects.equals(signature, that.signature); } X509SignedMessage(final String signedData, final String s...
@Test public void isEquals() { X509SignedMessage first = new X509SignedMessage("First Test", "First Signature"); X509SignedMessage second = new X509SignedMessage("Second Test", "Second Signature"); assertThat(first.equals(first), is(true)); assertThat(first.equals(second), is(false)); }
LoggingHandlerAdapter implements LoggingHandler { @Override public void log(final StatementInfo statementInfo, final ResultInfo resultInfo) { loggerContext.logQuery(statementInfo, resultInfo); } @Autowired LoggingHandlerAdapter(final LoggerContext loggerContext); @Override void log(final StatementInfo statementInfo, f...
@Test public void log() throws Exception { subject = new LoggingHandlerAdapter(loggerContext); subject.log(statementInfo, resultInfo); verify(loggerContext, times(1)).logQuery(statementInfo, resultInfo); }
UpdateLog { public void logUpdateResult(final UpdateRequest updateRequest, final UpdateContext updateContext, final Update update, final Stopwatch stopwatch) { logger.info(formatMessage(updateRequest, updateContext, update, stopwatch)); } UpdateLog(); UpdateLog(final Logger logger); void logUpdateResult(final UpdateRe...
@Test public void logUpdateResult_create_success() { final RpslObject maintainer = RpslObject.parse("mntner: TST-MNT"); final UpdateResult updateResult = new UpdateResult(maintainer, maintainer, Action.CREATE, UpdateStatus.SUCCESS, new ObjectMessages(), 0, false); when(update.getCredentials()).thenReturn(new Credential...
AuditLogger { public void logException(final Update update, final Throwable throwable) { final Element updateElement = createOrGetUpdateElement(update); final Element exceptionElement = doc.createElement("exception"); updateElement.appendChild(exceptionElement); exceptionElement.appendChild(keyValue("class", throwable....
@Test public void logException() throws Exception { subject.logUpdate(update); subject.logException(update, new NullPointerException()); subject.close(); final String log = outputStream.toString("UTF-8"); assertThat(log, containsString("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<dbupdate c...
AuditLogger { public void logDuration(final Update update, final String duration) { final Element updateElement = createOrGetUpdateElement(update); updateElement.appendChild(keyValue("duration", duration)); } AuditLogger(final DateTimeProvider dateTimeProvider, final OutputStream outputStream); @SuppressWarnings("Throw...
@Test public void logDuration() throws Exception { subject.logUpdate(update); subject.logDuration(update, "1 ns"); subject.close(); final String log = outputStream.toString("UTF-8"); assertThat(log, containsString("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<dbupdate created=\"2012-12-01 00...
AuditLogger { public void logQuery(final Update update, final StatementInfo statementInfo, final ResultInfo resultInfo) { final Element updateElement = createOrGetUpdateElement(update); final Element queryElement = doc.createElement("query"); updateElement.appendChild(queryElement); queryElement.appendChild(keyValue("s...
@Test public void logQuery() throws Exception { final Map<Integer, Object> params = Maps.newTreeMap(); params.put(1, "p1"); params.put(2, 22); final List<List<String>> rows = Arrays.asList( Arrays.asList("c1-1", "c1-2"), Arrays.asList("c2-1", "c2-2")); final StatementInfo statementInfo = new StatementInfo("sql", params...
AuditLogger { public void close() { try { writeAndClose(); } catch (IOException e) { LOGGER.error("IO Exception", e); } } AuditLogger(final DateTimeProvider dateTimeProvider, final OutputStream outputStream); @SuppressWarnings("ThrowableResultOfMethodCallIgnored" /* Throwable is logged */) void log(final Message messag...
@Test public void empty() throws Exception { subject.close(); assertThat(outputStream.toString("UTF-8"), is("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<dbupdate created=\"2012-12-01 00:00:00\">\n" + " <messages/>\n" + " <updates/>\n" + "</dbupdate>\n" )); verify(outputStream, times(1)).clo...
LoggerContext { public void checkDirs() { getCreatedDir(baseDir); } @Autowired LoggerContext(final DateTimeProvider dateTimeProvider); void setBaseDir(final String baseDir); @PostConstruct void start(); void checkDirs(); void init(final String folderName); void remove(); File getFile(final String filename); File log(f...
@Test public void checkDirs() { subject.remove(); final File f = new File(folder.getRoot(), "test/"); subject.setBaseDir(f.getAbsolutePath()); subject.checkDirs(); subject.init("folder"); assertThat(f.exists(), is(true)); }
LoggerContext { public File getFile(final String filename) { final Context tempContext = getContext(); return getFile(tempContext.baseDir, tempContext.nextFileNumber(), filename); } @Autowired LoggerContext(final DateTimeProvider dateTimeProvider); void setBaseDir(final String baseDir); @PostConstruct void start(); vo...
@Test public void getFile() throws Exception { assertThat(subject.getFile("test.txt").getName(), is("001.test.txt.gz")); assertThat(subject.getFile("test.txt").getName(), is("002.test.txt.gz")); assertThat(subject.getFile("test.txt").getName(), is("003.test.txt.gz")); }
LoggerContext { public File log(final String name, final LogCallback callback) { final File file = getFile(name); OutputStream os = null; try { os = getOutputstream(file); callback.log(os); } catch (IOException e) { throw new IllegalStateException("Unable to write to " + file.getAbsolutePath(), e); } finally { closeOut...
@Test public void log() throws Exception { final File file = subject.log("test.txt", new LogCallback() { @Override public void log(final OutputStream outputStream) throws IOException { outputStream.write("test".getBytes()); } }); final InputStream is = new GZIPInputStream(new BufferedInputStream(new FileInputStream(new...
LoggerContext { public void logQuery(final StatementInfo statementInfo, final ResultInfo resultInfo) { final Context ctx = context.get(); if (ctx != null && ctx.currentUpdate != null) { ctx.auditLogger.logQuery(ctx.currentUpdate, statementInfo, resultInfo); } } @Autowired LoggerContext(final DateTimeProvider dateTimeP...
@Test public void log_query_no_context_should_not_fail() { subject.logQuery(new StatementInfo("sql"), new ResultInfo(Collections.<List<String>>emptyList())); }
LoggerContext { public void logUpdateCompleted(final UpdateContainer updateContainer) { logUpdateComplete(updateContainer, null); } @Autowired LoggerContext(final DateTimeProvider dateTimeProvider); void setBaseDir(final String baseDir); @PostConstruct void start(); void checkDirs(); void init(final String folderName)...
@Test(expected = IllegalStateException.class) public void logUpdateComplete_no_context_should_fail() { subject.logUpdateCompleted(update); }
LoggerContext { public void logException(final UpdateContainer updateContainer, final Throwable throwable) { getContext().auditLogger.logException(updateContainer.getUpdate(), throwable); } @Autowired LoggerContext(final DateTimeProvider dateTimeProvider); void setBaseDir(final String baseDir); @PostConstruct void sta...
@Test public void logException() throws IOException { final String content = "mntner: DEV-ROOT-MNT"; final RpslObject object = RpslObject.parse(content); when(update.getOperation()).thenReturn(Operation.DELETE); when(update.getParagraph()).thenReturn(new Paragraph(content)); when(update.getSubmittedObject()).thenReturn...
MailMessageLogCallback implements LogCallback { @Override public void log(final OutputStream outputStream) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { message.writeTo(baos); String messageData = new String( baos.toByteArray(), "UTF-8" ); String filtered = PasswordFilter.filterPa...
@Test public void log() throws IOException, MessagingException { final MailMessageLogCallback subject = new MailMessageLogCallback(message); subject.log(outputStream); verify(outputStream).write("".getBytes()); } @Test public void log_never_throws_exception() throws IOException, MessagingException { final MailMessageLo...
IterableTransformer implements Iterable<T> { @Override public Iterator<T> iterator() { return new IteratorTransformer(head); } IterableTransformer(final Iterable<? extends T> wrap); IterableTransformer<T> setHeader(T... header); IterableTransformer<T> setHeader(Collection<T> header); abstract void apply(final T input, ...
@Test public void empty_input_test() { final Iterable subject = getSimpleIterable(); final Iterator<Integer> iterator = subject.iterator(); assertFalse(iterator.hasNext()); } @Test(expected = NullPointerException.class) public void null_test() { final Iterable<Integer> subject = getSimpleIterable(1, null, 2, null); fin...
GrsImporter implements DailyScheduledTask { @Override @Scheduled(cron = "0 0 0 * * *") @SchedulerLock(name = "GrsImporter") public void run() { if (!grsImportEnabled) { LOGGER.info("GRS import is not enabled"); return; } List<Future> futures = grsImport(defaultSources, false); for (Future future : futures) { try { futu...
@Test public void run() { subject = spy(subject); subject.setGrsImportEnabled(false); subject.run(); verify(subject, times(0)).grsImport(anyString(), anyBoolean()); }
MailGatewaySmtp implements MailGateway { @Override public void sendEmail(final String to, final ResponseMessage responseMessage) { sendEmail(to, responseMessage.getSubject(), responseMessage.getMessage(), responseMessage.getReplyTo()); } @Autowired MailGatewaySmtp(final LoggerContext loggerContext, final MailConfigura...
@Test public void sendResponse() throws Exception { subject.sendEmail("to", "subject", "test", ""); verify(mailSender, times(1)).send(any(MimeMessagePreparator.class)); } @Test public void sendResponse_disabled() throws Exception { ReflectionTestUtils.setField(subject, "outgoingMailEnabled", false); subject.sendEmail("...
OverrideCredential implements Credential { @Override public String toString() { if (!overrideValues.isPresent()){ return "OverrideCredential{NOT_VALID}"; } if (StringUtils.isBlank(overrideValues.get().getRemarks())){ return String.format("OverrideCredential{%s,FILTERED}", overrideValues.get().getUsername()); } return S...
@Test public void testToString() { assertThat(OverrideCredential.parse("").toString(), is("OverrideCredential{NOT_VALID}")); assertThat(OverrideCredential.parse("user").toString(), is("OverrideCredential{NOT_VALID}")); assertThat(OverrideCredential.parse("user,password").toString(), is("OverrideCredential{user,FILTERED...
LegacyAutnum { public boolean contains(final CIString autnum) { return cachedLegacyAutnums.contains(autnum); } @Autowired LegacyAutnum(final LegacyAutnumDao legacyAutnumDao); @PostConstruct synchronized void init(); boolean contains(final CIString autnum); int getTotal(); }
@Test public void contains() { assertThat(subject.contains(ciString("AS100")), is(false)); assertThat(subject.contains(ciString("AS102")), is(true)); }
OrganisationId extends AutoKey { @Override public String toString() { return new StringBuilder() .append("ORG-") .append(getSpace().toUpperCase()) .append(getIndex()) .append("-") .append(getSuffix()) .toString(); } OrganisationId(final String space, final int index, final String suffix); @Override String toString(); ...
@Test public void string() { final OrganisationId subject = new OrganisationId("SAT", 1, "RIPE"); assertThat(subject.toString(), is("ORG-SAT1-RIPE")); }
NicHandle extends AutoKey { public static NicHandle parse(final String nicHdl, final CIString source, final Set<CIString> countryCodes) { if (StringUtils.startsWithIgnoreCase(nicHdl, "AUTO-")) { throw new NicHandleParseException("Primary key generation request cannot be parsed as NIC-HDL: " + nicHdl); } final Matcher m...
@Test public void parse_auto() { try { NicHandle.parse("AUTO-1", source, countryCodes); fail("AUTO- should not be supported as NIC-HDL"); } catch (NicHandleParseException e) { assertThat(e.getMessage(), is("Primary key generation request cannot be parsed as NIC-HDL: AUTO-1")); } } @Test public void parse_auto_lowercase...
UpdateContext { public Messages getGlobalMessages() { return globalMessages; } UpdateContext(final LoggerContext loggerContext); boolean isDryRun(); void dryRun(); int getNrSinceRestart(); boolean isBatchUpdate(); void setBatchUpdate(); void addDnsCheckResponse(final DnsCheckRequest request, final DnsCheckResponse resp...
@Test public void no_warnings() { assertThat(subject.getGlobalMessages().getAllMessages(), hasSize(0)); }
UpdateContext { public boolean hasErrors(final UpdateContainer updateContainer) { return getOrCreateContext(updateContainer).objectMessages.hasErrors(); } UpdateContext(final LoggerContext loggerContext); boolean isDryRun(); void dryRun(); int getNrSinceRestart(); boolean isBatchUpdate(); void setBatchUpdate(); void ad...
@Test public void no_errors() { final RpslObject mntner = RpslObject.parse(MAINTAINER); final Update update = new Update(new Paragraph(MAINTAINER), Operation.DELETE, Lists.<String>newArrayList(), mntner); final PreparedUpdate preparedUpdate = new PreparedUpdate(update, null, mntner, Action.DELETE); assertThat(subject.h...
UpdateContext { public void status(final UpdateContainer updateContainer, final UpdateStatus status) { getOrCreateContext(updateContainer).status = status; loggerContext.logStatus(updateContainer, status); } UpdateContext(final LoggerContext loggerContext); boolean isDryRun(); void dryRun(); int getNrSinceRestart(); bo...
@Test public void status() { final String content = "mntner: DEV-ROOT-MNT"; final RpslObject mntner = RpslObject.parse(content); final Update update = new Update(new Paragraph(content), Operation.DELETE, Lists.<String>newArrayList(), mntner); final PreparedUpdate preparedUpdate = new PreparedUpdate(update, null, mntner...
UpdateContext { public Ack createAck() { final List<UpdateResult> updateResults = Lists.newArrayList(); for (final Update update : contexts.keySet()) { updateResults.add(createUpdateResult(update)); } final List<Paragraph> ignoredParagraphs = getIgnoredParagraphs(); return new Ack(updateResults, ignoredParagraphs); } U...
@Test public void createAck() { final RpslObject object = RpslObject.parse(MAINTAINER); final Update delete = new Update(new Paragraph(MAINTAINER), Operation.DELETE, Lists.<String>newArrayList(), object); subject.setAction(delete, Action.DELETE); final Update deleteWithError = new Update(new Paragraph(MAINTAINER), Oper...
ContentWithCredentials { public List<Credential> getCredentials() { return credentials; } ContentWithCredentials(final String content); ContentWithCredentials(final String content, final Charset charset); ContentWithCredentials(final String content, final List<Credential> credentials); ContentWithCredentials(final S...
@Test(expected = UnsupportedOperationException.class) public void credentials_are_immutable() { final ContentWithCredentials subject = new ContentWithCredentials("test", Lists.newArrayList(credential)); subject.getCredentials().add(mock(Credential.class)); }
PreparedUpdate implements UpdateContainer { @Override public Update getUpdate() { return update; } PreparedUpdate(final Update update, @Nullable final RpslObject originalObject, @Nullable final RpslObject updatedObject, final Action action); PreparedUpdate(final Update update, @Nullable final RpslObject originalObject...
@Test public void getUpdate() { assertThat(subject.getUpdate(), is(update)); }
PreparedUpdate implements UpdateContainer { public Paragraph getParagraph() { return update.getParagraph(); } PreparedUpdate(final Update update, @Nullable final RpslObject originalObject, @Nullable final RpslObject updatedObject, final Action action); PreparedUpdate(final Update update, @Nullable final RpslObject ori...
@Test public void getParagraph() { subject.getParagraph(); verify(update).getParagraph(); }
PreparedUpdate implements UpdateContainer { @Nullable public RpslObject getReferenceObject() { if (originalObject != null) { return originalObject; } return updatedObject; } PreparedUpdate(final Update update, @Nullable final RpslObject originalObject, @Nullable final RpslObject updatedObject, final Action action); Pr...
@Test public void getOriginalObject() { assertThat(subject.getReferenceObject(), is(originalObject)); }
PreparedUpdate implements UpdateContainer { @Nullable public RpslObject getUpdatedObject() { return updatedObject; } PreparedUpdate(final Update update, @Nullable final RpslObject originalObject, @Nullable final RpslObject updatedObject, final Action action); PreparedUpdate(final Update update, @Nullable final RpslObj...
@Test public void getUpdatedObject() { assertThat(subject.getUpdatedObject(), is(updatedObject)); }
PreparedUpdate implements UpdateContainer { public Action getAction() { return action; } PreparedUpdate(final Update update, @Nullable final RpslObject originalObject, @Nullable final RpslObject updatedObject, final Action action); PreparedUpdate(final Update update, @Nullable final RpslObject originalObject, @Nullabl...
@Test public void getAction() { assertThat(subject.getAction(), is(Action.MODIFY)); }
PreparedUpdate implements UpdateContainer { public Credentials getCredentials() { return update.getCredentials(); } PreparedUpdate(final Update update, @Nullable final RpslObject originalObject, @Nullable final RpslObject updatedObject, final Action action); PreparedUpdate(final Update update, @Nullable final RpslObje...
@Test public void getCredentials() { subject.getCredentials(); verify(update).getCredentials(); }
PreparedUpdate implements UpdateContainer { public ObjectType getType() { return update.getType(); } PreparedUpdate(final Update update, @Nullable final RpslObject originalObject, @Nullable final RpslObject updatedObject, final Action action); PreparedUpdate(final Update update, @Nullable final RpslObject originalObje...
@Test public void getType() { subject.getType(); verify(update).getType(); }
PreparedUpdate implements UpdateContainer { public String getKey() { return updatedObject.getKey().toString(); } PreparedUpdate(final Update update, @Nullable final RpslObject originalObject, @Nullable final RpslObject updatedObject, final Action action); PreparedUpdate(final Update update, @Nullable final RpslObject ...
@Test public void getKey() { assertThat(subject.getFormattedKey(), is("[mntner] DEV-TST-MNT")); }
PreparedUpdate implements UpdateContainer { public Set<CIString> getNewValues(final AttributeType attributeType) { final Set<CIString> newValues = updatedObject.getValuesForAttribute(attributeType); if (originalObject != null) { newValues.removeAll(originalObject.getValuesForAttribute(attributeType)); } return newValue...
@Test public void newValues_create() { subject = new PreparedUpdate( update, null, RpslObject.parse("" + "inetnum: 10.0.0.0\n" + "mnt-by: DEV-MNT-1\n" + "mnt-by: DEV-MNT-2\n"), Action.CREATE); final Set<CIString> newValues = subject.getNewValues(AttributeType.MNT_BY); assertThat(newValues, contains(ciString("DEV-MNT-1"...
PreparedUpdate implements UpdateContainer { public Set<CIString> getDifferences(final AttributeType attributeType) { Set<CIString> differences = updatedObject.getValuesForAttribute(attributeType); if (originalObject != null && !Action.DELETE.equals(action)) { differences = Sets.symmetricDifference(differences, original...
@Test public void differentValues_create() { subject = new PreparedUpdate( update, null, RpslObject.parse("" + "inetnum: 10.0.0.0\n" + "mnt-by: DEV-MNT-1\n" + "mnt-by: DEV-MNT-2\n"), Action.CREATE); final Set<CIString> differences = subject.getDifferences(AttributeType.MNT_BY); assertThat(differences, contains(ciString...
UpdateMessages { public static Message authenticationFailed(final RpslObject object, final AttributeType attributeType, final Iterable<RpslObject> candidates) { final CharSequence joined = LIST_JOINED.join( Iterables.transform(candidates,input -> input == null ? "" : input.getKey())); return new Message(Type.ERROR, "" ...
@Test public void authentication_failed_empty_list() { RpslObject object = RpslObject.parse("person: New Person\nnic-hdl: AUTO-1"); final Message result = UpdateMessages.authenticationFailed(object, AttributeType.MNT_BY, Lists.<RpslObject>newArrayList()); assertThat(result.toString(), is( "Authorisation for [person] AU...
ObjectKey { @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final ObjectKey that = (ObjectKey) o; return Objects.equals(objectType, that.objectType) && Objects.equals(pkey, that.pkey); } ObjectKey(final ObjectType objectType, final Strin...
@Test public void equals() { final ObjectKey subject = new ObjectKey(ObjectType.MNTNER, "key"); assertThat(subject.equals(null), is(false)); assertThat(subject.equals(""), is(false)); assertThat(subject.equals(subject), is(true)); assertThat(subject.equals(new ObjectKey(ObjectType.MNTNER, "key")), is(true)); assertThat...
ObjectKey { @Override public int hashCode() { return Objects.hash(objectType, pkey); } ObjectKey(final ObjectType objectType, final String pkey); ObjectKey(final ObjectType objectType, final CIString pkey); ObjectType getObjectType(); CIString getPkey(); @Override boolean equals(Object o); @Override int hashCode(); @O...
@Test public void hash() { final ObjectKey subject = new ObjectKey(ObjectType.MNTNER, "key"); assertThat(subject.hashCode(), is(new ObjectKey(ObjectType.MNTNER, "key").hashCode())); assertThat(subject.hashCode(), not(is(new ObjectKey(ObjectType.ORGANISATION, "key").hashCode()))); } @Test public void hash_uppercase() { ...
ObjectKey { @Override public String toString() { return String.format("[%s] %s", objectType.getName(), pkey); } ObjectKey(final ObjectType objectType, final String pkey); ObjectKey(final ObjectType objectType, final CIString pkey); ObjectType getObjectType(); CIString getPkey(); @Override boolean equals(Object o); @Ov...
@Test public void string() { final ObjectKey subject = new ObjectKey(ObjectType.MNTNER, "key"); assertThat(subject.toString(), is("[mntner] key")); } @Test public void string_uppercase() { final ObjectKey subject = new ObjectKey(ObjectType.MNTNER, "KeY"); assertThat(subject.toString(), is("[mntner] KeY")); }
Notification { public String getEmail() { return email; } Notification(final String email); void add(final Type type, final PreparedUpdate update, UpdateContext updateContext); String getEmail(); Set<Update> getUpdates(final Type type); boolean has(final Type type); }
@Test public void getEmail() { assertThat(subject.getEmail(), is("test@me.now")); }