Search in sources :

Example 1 with MainConfig

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")));
}
Also used : UnknownHostException(java.net.UnknownHostException) MainConfig(org.nzbhydra.config.MainConfig) InetAddress(java.net.InetAddress)

Example 2 with MainConfig

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());
}
Also used : ChangelogChangeEntry(org.nzbhydra.mapping.changelog.ChangelogChangeEntry) ChangelogVersionEntry(org.nzbhydra.mapping.changelog.ChangelogVersionEntry) MainConfig(org.nzbhydra.config.MainConfig) TypeReference(com.fasterxml.jackson.core.type.TypeReference) BaseConfig(org.nzbhydra.config.BaseConfig) BlockedVersion(org.nzbhydra.update.UpdateManager.BlockedVersion) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Release(org.nzbhydra.mapping.github.Release) Before(org.junit.Before)

Example 3 with MainConfig

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());
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) StreamResult(javax.xml.transform.stream.StreamResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) MainConfig(org.nzbhydra.config.MainConfig) Before(org.junit.Before)

Example 4 with MainConfig

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");
}
Also used : MainConfig(org.nzbhydra.config.MainConfig) Before(org.junit.Before)

Example 5 with MainConfig

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());
}
Also used : MainConfig(org.nzbhydra.config.MainConfig) EventListener(org.springframework.context.event.EventListener)

Aggregations

MainConfig (org.nzbhydra.config.MainConfig)11 Before (org.junit.Before)3 InetSocketAddress (java.net.InetSocketAddress)2 Proxy (java.net.Proxy)2 Builder (okhttp3.OkHttpClient.Builder)2 Response (okhttp3.Response)2 Route (okhttp3.Route)2 SocksProxy (sockslib.client.SocksProxy)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PostConstruct (javax.annotation.PostConstruct)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 BaseConfig (org.nzbhydra.config.BaseConfig)1