use of org.nzbhydra.config.MainConfig in project nzbhydra2 by theotherp.
the class HydraOkHttp3ClientHttpRequestFactory method isUriToBeIgnoredByProxy.
protected boolean isUriToBeIgnoredByProxy(String host) {
MainConfig mainConfig = configProvider.getBaseConfig().getMain();
if (mainConfig.isProxyIgnoreLocal()) {
if (InetAddresses.isInetAddress(host)) {
try {
InetAddress byName = InetAddress.getByName(host);
long ipToLong = ipToLong(byName);
return host.equals("127.0.0.1") || (ipToLong >= ipToLong(InetAddress.getByName("10.0.0.0")) && ipToLong <= ipToLong(InetAddress.getByName("10.255.255.255"))) || (ipToLong >= ipToLong(InetAddress.getByName("172.16.0.0")) && ipToLong <= ipToLong(InetAddress.getByName("172.16.255.255"))) || (ipToLong >= ipToLong(InetAddress.getByName("192.168.0.0")) && ipToLong <= ipToLong(InetAddress.getByName("192.168.255.255")));
} catch (UnknownHostException e) {
logger.error("Unable to parse host " + host, e);
return false;
}
}
if (host.equals("localhost")) {
return true;
}
}
if (mainConfig.getProxyIgnoreDomains() == null || mainConfig.getProxyIgnoreDomains().isEmpty()) {
return false;
}
return mainConfig.getProxyIgnoreDomains().stream().anyMatch(x -> host.toLowerCase().matches(("\\Q" + x.toLowerCase() + "\\E").replace("*", "\\E.*\\Q")));
}
use of org.nzbhydra.config.MainConfig in project nzbhydra2 by theotherp.
the class UpdateManagerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
objectMapper = new ObjectMapper();
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
baseConfig = new BaseConfig();
MainConfig main = new MainConfig();
main.setUpdateToPrereleases(false);
baseConfig.setMain(main);
when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
testee.currentVersionString = "1.0.0";
testee.repositoryBaseUrl = "http:/127.0.0.1:7070/repos/theotherp/apitests";
testee.changelogUrl = "http:/127.0.0.1:7070/changelog";
testee.blockedVersionsUrl = "http:/127.0.0.1:7070/blockedVersions.json";
testee.afterPropertiesSet();
Release prerelease = new Release();
prerelease.setTagName("v2.3.4");
prerelease.setBody("Some new stuff as prerelease");
prerelease.setPrerelease(true);
Release latestRelease = new Release();
latestRelease.setTagName("v2.0.0");
latestRelease.setBody("Some new stuff");
latestRelease.setPrerelease(false);
Release previousRelease = new Release();
previousRelease.setTagName("v1.0.0");
previousRelease.setBody("A list:\n" + "* a\n" + "* b");
previousRelease.setPrerelease(false);
when(webAccessMock.callUrl(eq("http:/127.0.0.1:7070/repos/theotherp/apitests/releases"), any(TypeReference.class))).thenReturn(Arrays.asList(previousRelease, latestRelease, prerelease));
when(webAccessMock.callUrl(eq("http:/127.0.0.1:7070/changelog"))).thenReturn(objectMapper.writeValueAsString(Arrays.asList(new ChangelogVersionEntry("4.0.0", null, false, Arrays.asList(new ChangelogChangeEntry("note", "this is a prerelease"))), new ChangelogVersionEntry("3.0.0", null, true, Arrays.asList(new ChangelogChangeEntry("note", "a note"))), new ChangelogVersionEntry("2.0.0", null, true, Arrays.asList(new ChangelogChangeEntry("fix", "a minor fix"))), new ChangelogVersionEntry("0.0.1", null, true, Arrays.asList(new ChangelogChangeEntry("feature", "a new feature"))))));
when(webAccessMock.callUrl(eq("http:/127.0.0.1:7070/blockedVersions.json"))).thenReturn(objectMapper.writeValueAsString(Arrays.asList(new BlockedVersion("3.0.0", "comment"))));
when(genericStorage.get("UpdateData", UpdateData.class)).thenReturn(Optional.empty());
}
use of org.nzbhydra.config.MainConfig in project nzbhydra2 by theotherp.
the class ExternalApiTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(configProvider.getBaseConfig()).thenReturn(baseConfig);
baseConfig.setMain(new MainConfig());
baseConfig.getMain().setApiKey("apikey");
when(searchRequestFactory.getSearchRequest(any(), any(), any(), anyLong(), any(), any())).thenReturn(new SearchRequest(SearchSource.API, SearchType.SEARCH, 0, 100));
when(searchRequestFactory.extendWithSavedIdentifiers(any())).thenAnswer(x -> x.getArguments()[0]);
when(searcher.search(any())).thenReturn(searchResult);
when(searchResult.getNumberOfAcceptedResults()).thenReturn(10);
when(searchResult.getNumberOfProcessedResults()).thenReturn(10);
when(searchResult.getNumberOfRejectedResults()).thenReturn(0);
when(searchResult.getNumberOfRemovedDuplicates()).thenReturn(0);
when(searchResult.getNumberOfTotalAvailableResults()).thenReturn(10);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
StreamResult streamResult = (StreamResult) invocation.getArguments()[1];
streamResult.getOutputStream().write("".getBytes(), 0, "".getBytes().length);
return null;
}
}).when(jaxb2MarshallerMock).marshal(any(), any());
when(indexerMock.getConfig()).thenReturn(indexerConfig);
when(newznabXmlTransformerMock.getRssRoot(any(), anyInt(), anyInt(), any())).thenReturn(new NewznabXmlRoot());
}
use of org.nzbhydra.config.MainConfig in project nzbhydra2 by theotherp.
the class NewznabXmlTransformerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(configProvider.getBaseConfig()).thenReturn(baseConfig);
baseConfig.setMain(new MainConfig());
baseConfig.getMain().setApiKey("apikey");
when(searchResult.getNumberOfAcceptedResults()).thenReturn(10);
when(searchResult.getNumberOfProcessedResults()).thenReturn(10);
when(searchResult.getNumberOfRejectedResults()).thenReturn(0);
when(searchResult.getNumberOfRemovedDuplicates()).thenReturn(0);
when(searchResult.getNumberOfTotalAvailableResults()).thenReturn(10);
when(indexerMock.getConfig()).thenReturn(indexerConfig);
indexerConfig.setHost("http://127.0.0.1");
}
use of org.nzbhydra.config.MainConfig in project nzbhydra2 by theotherp.
the class HydraOkHttp3ClientHttpRequestFactory method handleConfigChangedEvent.
@EventListener
public void handleConfigChangedEvent(ConfigChangedEvent event) {
MainConfig mainConfig = event.getNewConfig().getMain();
sockProxySocketFactory = new SockProxySocketFactory(mainConfig.getProxyHost(), mainConfig.getProxyPort(), mainConfig.getProxyUsername(), mainConfig.getProxyPassword());
}
Aggregations