public static final DLPAggregateId parse(String rawString) { Preconditions.checkArgument(rawString.startsWith(PREFIX + SEPARATOR)); return new DLPAggregateId(Domain.of( rawString.substring(PREFIX.length() + SEPARATOR.length()))); }
private void addEnvDomain() { String envDomain = envDetector.getEnv(ENV_DOMAIN); if (!Strings.isNullOrEmpty(envDomain)) { try { LOGGER.info("Adding environment defined domain {}", envDomain); addDomain(Domain.of(envDomain)); } catch (DomainListException e) { throw new RuntimeException(e); } } }
@Test public void getHeloNameShouldReturnDomainListDefaultDomainOnNullHeloName() throws DomainListException { when(domainList.getDefaultDomain()).thenReturn(Domain.of(DOMAIN)); HeloNameProvider heloNameProvider = new HeloNameProvider(null, domainList); assertThat(heloNameProvider.getHeloName()).isEqualTo(DOMAIN); }
@Test public void setDefaultDomainShouldCreateFromHostnameWhenEqualsToLocalhost() throws Exception { Domain expectedDefaultDomain = Domain.of(InetAddress.getLocalHost().getHostName()); domainList.configureDefaultDomain(expectedDefaultDomain); assertThat(domainList.getDomainListInternal()).contains(expectedDefaultDomain); }
@Test public void setDefaultDomainShouldNotCreateTwiceWhenCallingTwoTimes() throws Exception { Domain expectedDefaultDomain = Domain.of(InetAddress.getLocalHost().getHostName()); domainList.configureDefaultDomain(expectedDefaultDomain); domainList.configureDefaultDomain(expectedDefaultDomain); assertThat(domainList.getDomainListInternal()).containsOnlyOnce(expectedDefaultDomain); }
@Test void quotaRootWithDomainShouldBeWellSerialized() { assertThat(DTO_JSON_SERIALIZE.quotaRootWrites().writes(QuotaRoot.quotaRoot("bob@domain.tld", Optional.of(Domain.of("domain.tld"))))) .isEqualTo(new JsString("bob@domain.tld")); }
@Test public void processShouldResetMailStateToGhostWhenCanNotBuildNewRecipient() throws Exception { when(virtualTableStore.getMappings(any(String.class), any(Domain.class))).thenReturn(mappings); when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES_LOCAL)); mail = FakeMail.builder() .mimeMessage(message) .recipients(MailAddressFixture.OTHER_AT_JAMES, nonDomainWithDefaultLocal) .build(); processor.processMail(mail); assertThat(mail.getState()).isEqualTo(Mail.GHOST); assertThat(mail.getRecipients()).isEmpty(); }
@Test void quotaRootWithDomainShouldBeWellDeSerialized() { assertThat(DTO_JSON_SERIALIZE.quotaRootReads().reads(new JsString("bob@domain.tld")).get()) .isEqualTo(QuotaRoot.quotaRoot("bob@domain.tld", Optional.of(Domain.of("domain.tld")))); }
@Test public void testGetDomains() throws Exception { XMLDomainList dom = new XMLDomainList(setUpDNSServer("localhost")); dom.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .addConfiguredDomains(Domain.of("domain1."), Domain.of("domain2.")) .defaultDomain(DEFAULT_DOMAIN)); assertThat(dom.getDomains()).hasSize(3); }
@Test public void getDomainsShouldListAddedDomain() throws Exception { Domain defaultDomain = Domain.of("default.tld"); Domain domain = Domain.of("added.tld"); domainList.addDomain(domain); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(defaultDomain)); assertThat(domainList.getDomains()).containsOnly(domain, defaultDomain); }
@Test public void containsDomainShouldNotInteractWithDNSWhenDisabled() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false)); domainList.containsDomain(Domain.of("added.tld")); verifyZeroInteractions(dnsService); }
@Test public void testStoreAndGetMappings() throws ErrorMappingException, RecipientRewriteTableException { Domain domain = Domain.of("test"); virtualUserTable.addMapping(MappingSource.fromDomain(domain), Mapping.regex("prefix_.*:admin@test")); assertThat(virtualUserTable.getMappings("prefix_abc", domain)).isNotEmpty(); }
@Test void fromShouldReturnDomainMatchWhenOnlyDomain() { QuotaQuery query = QuotaQuery.builder().hasDomain(Domain.of("my.tld")).build(); QueryBuilder expected = termQuery(JsonMessageConstants.DOMAIN, "my.tld"); QueryBuilder actual = testee.from(query); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test public void testGetDomainsAutoDetectNotLocalHost() throws Exception { XMLDomainList dom = new XMLDomainList(setUpDNSServer("local")); dom.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(false) .addConfiguredDomains(Domain.of("domain1.")) .defaultDomain(DEFAULT_DOMAIN)); assertThat(dom.getDomains()).hasSize(3); }
@Test public void handleMappingsShouldRemoveMappingElementWhenCannotCreateMailAddress() throws Exception { when(domainList.getDefaultDomain()).thenReturn(Domain.of(MailAddressFixture.JAMES_LOCAL)); mappings = MappingsImpl.builder() .add(MailAddressFixture.ANY_AT_JAMES.toString()) .add(NONEDOMAIN) .add(INVALID_MAIL_ADDRESS) .add(MailAddressFixture.OTHER_AT_JAMES.toString()) .build(); Collection<MailAddress> result = processor.handleMappings(mappings, mail, MailAddressFixture.OTHER_AT_JAMES); assertThat(result).containsOnly(nonDomainWithDefaultLocal); }
@Test public void isLocalUserShouldReturnFalseWhenUsedWithLocalPartAndUserDoNotExistOnDefaultDomain() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(Domain.of("any")) .build()); domainList.addDomain(DOMAIN_COM); usersRepository.addUser(USERMAIL, PASSWORD); assertThat(testee.isLocalUser(USERNAME)).isFalse(); }
@Test public void builderShouldPutDomainAliasFirstThenForwardWhenVariousMappings() { Mapping regexMapping = Mapping.regex("regex"); Mapping forwardMapping = Mapping.forward("forward"); Mapping domainMapping = Mapping.domain(Domain.of("domain")); MappingsImpl mappingsImpl = MappingsImpl.builder() .add(regexMapping) .add(forwardMapping) .add(domainMapping) .build(); assertThat(mappingsImpl).containsExactly(domainMapping, forwardMapping, regexMapping); }
@BeforeEach void setup() throws Exception { super.setUp(); memoryRecipientRewriteTable.addErrorMapping(MappingSource.fromUser("error", DOMAIN), "disabled"); memoryRecipientRewriteTable.addRegexMapping(MappingSource.fromUser("regex", DOMAIN), ".*@b\\.com"); memoryRecipientRewriteTable.addAliasDomainMapping(MappingSource.fromDomain(Domain.of("alias")), DOMAIN); }
@BeforeEach void setup() throws Exception { super.setUp(); memoryRecipientRewriteTable.addErrorMapping(MappingSource.fromUser("error", DOMAIN), "disabled"); memoryRecipientRewriteTable.addRegexMapping(MappingSource.fromUser("regex", DOMAIN), ".*@b\\.com"); memoryRecipientRewriteTable.addAliasDomainMapping(MappingSource.fromDomain(Domain.of("alias")), DOMAIN); }
@Test public void addDomainShouldFailWhenAlreadyConfigured() throws Exception { expectedException.expect(DomainListException.class); XMLDomainList testee = new XMLDomainList(setUpDNSServer("hostname")); testee.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(false) .addConfiguredDomain(DOMAIN_1) .defaultDomain(DEFAULT_DOMAIN)); testee.addDomain(Domain.of("newDomain")); }