Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add corporate proxy workaround for Version.getAllAvailableVersions() #7890

Merged
merged 2 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where a title with multiple applied formattings in EndNote was not imported correctly [forum#2734](https://discourse.jabref.org/t/importing-endnote-label-field-to-jabref-from-xml-file/2734)
- We fixed an issue where a `report` in EndNote was imported as `article` [forum#2734](https://discourse.jabref.org/t/importing-endnote-label-field-to-jabref-from-xml-file/2734)
- We fixed an issue where the field `publisher` in EndNote was not imported in JabRef [forum#2734](https://discourse.jabref.org/t/importing-endnote-label-field-to-jabref-from-xml-file/2734)
- We fixed an issue when checking for a new version when JabRef is used behind a corporate proxy. [#7884](https://github.com/JabRef/jabref/issues/7884)

### Removed

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/jabref/logic/util/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jabref.logic.net.URLDownload;

import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject;
import org.slf4j.Logger;
Expand Down Expand Up @@ -94,12 +96,12 @@ public static Version parse(String version) {
* Grabs all the available releases from the GitHub repository
*/
public static List<Version> getAllAvailableVersions() throws IOException {
URLDownload.bypassSSLVerification();
HttpURLConnection connection = (HttpURLConnection) new URL(JABREF_GITHUB_RELEASES).openConnection();
connection.setRequestProperty("Accept-Charset", "UTF-8");
try (BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {

List<Version> versions = new ArrayList<>();
JSONArray objects = new JSONArray(rd.readLine());
List<Version> versions = new ArrayList<>(objects.length());
for (int i = 0; i < objects.length(); i++) {
JSONObject jsonObject = objects.getJSONObject(i);
Version version = Version.parse(jsonObject.getString("tag_name").replaceFirst("v", ""));
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/jabref/logic/util/VersionTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.jabref.logic.util;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.jabref.support.DisabledOnCIServer;
import org.jabref.testutils.category.FetcherTest;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class VersionTest {
Expand Down Expand Up @@ -294,4 +299,11 @@ public void ciSuffixShouldBeRemovedIfDateIsPresent() {
Version v50ci = Version.parse("5.0-ci.1--2020-03-06--289142f");
assertEquals("5.0--2020-03-06--289142f", v50ci.getFullVersion());
}

@Test
@FetcherTest
@DisabledOnCIServer("GitHub puts a low rate limit on unauthenticated calls")
public void getAllAvailableVersionsReturnsSomething() throws Exception {
assertNotEquals(Collections.emptyList(), Version.getAllAvailableVersions());
}
}