fix(plugins): improve errors handling and reporting (#2597)
This commit is contained in:
+78
@@ -0,0 +1,78 @@
|
||||
package jadx.plugins.tools.resolvers.github;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import mockwebserver3.MockResponse;
|
||||
import mockwebserver3.MockWebServer;
|
||||
|
||||
import jadx.core.utils.files.FileUtils;
|
||||
import jadx.plugins.tools.resolvers.github.data.Release;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class GithubToolsTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GithubToolsTest.class);
|
||||
|
||||
private MockWebServer server;
|
||||
private GithubTools githubTools;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws IOException {
|
||||
server = new MockWebServer();
|
||||
server.start();
|
||||
String baseUrl = server.url("/").toString();
|
||||
githubTools = new GithubTools(baseUrl);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void close() {
|
||||
server.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getReleaseGood() {
|
||||
server.enqueue(new MockResponse.Builder()
|
||||
.body(loadFromResource("plugins-list-good.json"))
|
||||
.build());
|
||||
|
||||
LocationInfo pluginsList = new LocationInfo("jadx-decompiler", "jadx-plugins-list", "list");
|
||||
Release release = githubTools.getRelease(pluginsList);
|
||||
|
||||
LOG.info("Result release: {}", release);
|
||||
assertThat(release.getName()).isEqualTo("v15");
|
||||
assertThat(release.getAssets()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getReleaseRateLimit() {
|
||||
server.enqueue(new MockResponse.Builder()
|
||||
.code(403)
|
||||
.addHeader("x-ratelimit-remaining", "0")
|
||||
.addHeader("x-ratelimit-reset", Instant.now().plusSeconds(60 * 60).getEpochSecond()) // 1 hour from now
|
||||
.body("{}")
|
||||
.build());
|
||||
|
||||
LocationInfo pluginsList = new LocationInfo("jadx-decompiler", "jadx-plugins-list", "list");
|
||||
Assertions.assertThatThrownBy(() -> githubTools.getRelease(pluginsList))
|
||||
.hasMessageContaining("403")
|
||||
.hasMessageContaining("Client Error")
|
||||
.hasMessageContaining("rate limit reached");
|
||||
}
|
||||
|
||||
private static String loadFromResource(String resName) {
|
||||
try (InputStream stream = GithubToolsTest.class.getResourceAsStream("/github/" + resName)) {
|
||||
return FileUtils.streamToString(stream);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to load resource: " + resName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"assets": [
|
||||
{
|
||||
"browser_download_url": "https://github.com/jadx-decompiler/jadx-plugins-list/releases/download/v15/jadx-plugins-list.zip",
|
||||
"content_type": "application/zip",
|
||||
"created_at": "2025-11-29T16:20:40Z",
|
||||
"digest": "sha256:a2a45c3a22be56b6f9c7e24d52c6411c4d546f386d7ea1e4ba124d4d28b4cf75",
|
||||
"download_count": 3412,
|
||||
"id": 322246364,
|
||||
"label": null,
|
||||
"name": "jadx-plugins-list.zip",
|
||||
"node_id": "RA_kwDOKEBYcM4TNRbc",
|
||||
"size": 1260,
|
||||
"state": "uploaded",
|
||||
"updated_at": "2025-11-29T16:20:42Z",
|
||||
"url": "https://api.github.com/repos/jadx-decompiler/jadx-plugins-list/releases/assets/322246364"
|
||||
}
|
||||
],
|
||||
"assets_url": "https://api.github.com/repos/jadx-decompiler/jadx-plugins-list/releases/266146702/assets",
|
||||
"body": "What's Changed...",
|
||||
"created_at": "2025-11-29T16:19:33Z",
|
||||
"draft": false,
|
||||
"html_url": "https://github.com/jadx-decompiler/jadx-plugins-list/releases/tag/v15",
|
||||
"id": 266146702,
|
||||
"immutable": false,
|
||||
"mentions_count": 1,
|
||||
"name": "v15",
|
||||
"node_id": "RE_kwDOKEBYcM4P3ROO",
|
||||
"prerelease": false,
|
||||
"published_at": "2025-11-29T16:20:50Z",
|
||||
"tag_name": "v15",
|
||||
"tarball_url": "https://api.github.com/repos/jadx-decompiler/jadx-plugins-list/tarball/v15",
|
||||
"target_commitish": "main",
|
||||
"updated_at": "2025-11-29T16:20:50Z",
|
||||
"upload_url": "https://uploads.github.com/repos/jadx-decompiler/jadx-plugins-list/releases/266146702/assets{?name,label}",
|
||||
"url": "https://api.github.com/repos/jadx-decompiler/jadx-plugins-list/releases/266146702",
|
||||
"zipball_url": "https://api.github.com/repos/jadx-decompiler/jadx-plugins-list/zipball/v15"
|
||||
}
|
||||
Reference in New Issue
Block a user