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

[JENKINS-73760] Updates fail due to invalid JSON from HTTP Update Center #9760

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions core/src/main/java/hudson/model/UpdateSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,17 @@ public String getDownloadUrl() {

/**
* Is this the legacy default update center site?
* @deprecated
* Will be removed, currently returns always false.
Comment on lines -541 to -542
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverting this hunk of #6116, since this functionality is useful and should not be deprecated.

* @since 2.343
* @since 1.357
Comment on lines -543 to +541
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just wrong. This method was introduced in 1.357.

*/
@Deprecated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverting this hunk of #6116, since this functionality is useful and should not be deprecated.

@Restricted(NoExternalUse.class)
public boolean isLegacyDefault() {
return false;
return isJenkinsCI();
}

private boolean isJenkinsCI() {
return url != null
&& UpdateCenter.PREDEFINED_UPDATE_SITE_ID.equals(id)
&& url.startsWith("http://updates.jenkins-ci.org/");
Comment on lines +548 to +551
Copy link
Member Author

@basil basil Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adapting the pre-#6116 code to handle the migration from http://updates.jenkins-ci.org to https://updates.jenkins.io rather than the migration from http://hudson-ci.org to http://updates.jenkins-ci.org

}

/**
Expand Down
35 changes: 35 additions & 0 deletions test/src/test/java/hudson/model/UpdateCenterMigrationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package hudson.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;

public class UpdateCenterMigrationTest {

@Rule
public JenkinsRule j = new JenkinsRule() {
@Override
protected void configureUpdateCenter() {
// Avoid reverse proxy
DownloadService.neverUpdate = true;
UpdateSite.neverUpdate = true;
}
};

@Issue("JENKINS-73760")
@LocalData
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hudson.model.UpdateCenter.xml taken from a stock 2.76 installation.

@Test
public void updateCenterMigration() {
UpdateSite site = j.jenkins.getUpdateCenter().getSites().stream()
.filter(s -> UpdateCenter.PREDEFINED_UPDATE_SITE_ID.equals(s.getId()))
.findFirst()
.orElseThrow();
assertFalse(site.isLegacyDefault());
assertEquals(j.jenkins.getUpdateCenter().getDefaultBaseUrl() + "update-center.json", site.getUrl());
}
}
14 changes: 14 additions & 0 deletions test/src/test/java/hudson/model/UpdateSiteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

public class UpdateSiteTest {
Expand Down Expand Up @@ -205,6 +206,19 @@ public void shutdownWebserver() throws Exception {
assertNotEquals("plugin data is present", Collections.emptyMap(), site.getData().plugins);
}

@Issue("JENKINS-73760")
@Test
public void isLegacyDefault() {
assertFalse("isLegacyDefault should be false with null id", new UpdateSite(null, "url").isLegacyDefault());
assertFalse(
"isLegacyDefault should be false when id is not default and url is http://updates.jenkins-ci.org/",
new UpdateSite("dummy", "http://updates.jenkins-ci.org/").isLegacyDefault());
assertTrue(
"isLegacyDefault should be true when id is default and url is http://updates.jenkins-ci.org/",
new UpdateSite(UpdateCenter.PREDEFINED_UPDATE_SITE_ID, "http://updates.jenkins-ci.org/").isLegacyDefault());
assertFalse("isLegacyDefault should be false with null url", new UpdateSite(null, null).isLegacyDefault());
}

Comment on lines +209 to +221
Copy link
Member Author

@basil basil Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adapting the pre-#6116 code to handle the migration from http://updates.jenkins-ci.org to https://updates.jenkins.io rather than the migration from http://hudson-ci.org to http://updates.jenkins-ci.org

@Test public void getAvailables() throws Exception {
UpdateSite site = getUpdateSite("/plugins/available-update-center.json");
List<UpdateSite.Plugin> available = site.getAvailables();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>http://updates.jenkins-ci.org/update-center.json</url>
</site>
</sites>
Loading