-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New dependencies on licensed extensions are not covered by existing l…
…icenses when upgrading licensed extensions #174 * refactoring and adding comments
- Loading branch information
1 parent
b37e5e1
commit e628a03
Showing
8 changed files
with
29 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ public class DefaultLicenseUpdater implements LicenseUpdater | |
private static final String DATA = "data"; | ||
|
||
private static final String ERROR = | ||
"Failed to update license for [{}]. Please contact [email protected] for eventual problems."; | ||
"Failed to update license for [%s]. Please contact your administrator for eventual problems."; | ||
|
||
private static final String FEATURE_ID = "featureId"; | ||
|
||
|
@@ -117,19 +117,18 @@ public class DefaultLicenseUpdater implements LicenseUpdater | |
@Override | ||
public void renewLicense(ExtensionId extensionId) | ||
{ | ||
String errorMsg = String.format(ERROR, extensionId); | ||
|
||
try { | ||
logger.debug("Try renewing the license of [{}], in order to include new found changes.", extensionId); | ||
|
||
String errorMsg = String.format( | ||
"Failed to update license for [%s]. Please contact [email protected] for eventual problems.", | ||
extensionId); | ||
JsonNode licenseRenewResponse = httpUtils.httpPost(initializeLicenseRenewPost(extensionId), errorMsg); | ||
if (licenseRenewResponse == null) { | ||
return; | ||
} | ||
|
||
if (licenseRenewResponse.get("status").textValue().equals("error")) { | ||
logger.warn(ERROR + " Cause: [{}]", extensionId.getId(), licenseRenewResponse.get(DATA).textValue()); | ||
logger.warn("{} Cause: [{}]", errorMsg, licenseRenewResponse.get(DATA).textValue()); | ||
} else { | ||
logger.debug( | ||
"Successful response from store after license renew. Trying to update local licenses too."); | ||
|
@@ -144,17 +143,17 @@ public void renewLicense(ExtensionId extensionId) | |
} else { | ||
logger.debug("No license received in store response. Updating all licenses in case there might " | ||
+ "have been updates anyway. Cause: [{}]", licenseRenewResponse.get(DATA)); | ||
getLicensesUpdates(); | ||
updateLicenses(); | ||
} | ||
} | ||
} catch (Exception e) { | ||
logger.warn(ERROR + " Root cause is [{}]", extensionId, ExceptionUtils.getRootCauseMessage(e)); | ||
logger.warn("{} Root cause is [{}]", errorMsg, ExceptionUtils.getRootCauseMessage(e)); | ||
} | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public void getLicensesUpdates() | ||
public void updateLicenses() | ||
{ | ||
try { | ||
URL licensesUpdateURL = getLicensesUpdatesURL(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ | |
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mock; | ||
import org.xwiki.crypto.BinaryStringEncoder; | ||
import org.xwiki.extension.ExtensionId; | ||
|
@@ -44,8 +43,6 @@ | |
import org.xwiki.test.junit5.mockito.InjectMockComponents; | ||
import org.xwiki.test.junit5.mockito.MockComponent; | ||
|
||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.xpn.xwiki.XWiki; | ||
|
@@ -185,24 +182,23 @@ void renewLicenseWithError() throws Exception | |
ExtensionId extensionId = new ExtensionId("application-test", "1.0"); | ||
licenseUpdater.renewLicense(extensionId); | ||
|
||
assertEquals(String.format("Failed to update license for [%s]. Please contact [email protected] for eventual " | ||
+ "problems. Cause: [error cause]", extensionId.getId()), | ||
logCaptureWarn.getMessage(0)); | ||
assertEquals(String.format("Failed to update license for [%s]. Please contact your administrator for eventual " | ||
+ "problems. Cause: [error cause]", extensionId), logCaptureWarn.getMessage(0)); | ||
} | ||
|
||
@Test | ||
void getLicensesUpdatesWithNullURL() throws Exception | ||
void updateLicensesWithNullURL() throws Exception | ||
{ | ||
when(licensingConfig.getStoreUpdateURL()).thenReturn(null); | ||
|
||
licenseUpdater.getLicensesUpdates(); | ||
licenseUpdater.updateLicenses(); | ||
|
||
assertEquals("Failed to update licenses because the licensor configuration is not complete. " | ||
+ "Check your store update URL.", logCaptureWarn.getMessage(0)); | ||
} | ||
|
||
@Test | ||
void getLicensesUpdatesWithUpdates() throws Exception | ||
void updateLicensesWithUpdates() throws Exception | ||
{ | ||
when(licensingConfig.getStoreUpdateURL()).thenReturn("https://storeUpdate.com"); | ||
|
||
|
@@ -223,13 +219,13 @@ void getLicensesUpdatesWithUpdates() throws Exception | |
License convertedLicense = new License(); | ||
when(converter.convert(License.class, licenseBytes)).thenReturn(convertedLicense); | ||
|
||
licenseUpdater.getLicensesUpdates(); | ||
licenseUpdater.updateLicenses(); | ||
|
||
verify(licenseManager).add(convertedLicense); | ||
} | ||
|
||
@Test | ||
void getLicensesUpdatesWithoutUpdates() throws IOException | ||
void updateLicensesWithoutUpdates() throws IOException | ||
{ | ||
when(licensingConfig.getStoreUpdateURL()).thenReturn("https://storeUpdate.com"); | ||
|
||
|
@@ -245,7 +241,7 @@ void getLicensesUpdatesWithoutUpdates() throws IOException | |
when(licensor.getLicense(licensedExtension)).thenReturn(license); | ||
when(license.getExpirationDate()).thenReturn(Long.valueOf("12")); | ||
|
||
licenseUpdater.getLicensesUpdates(); | ||
licenseUpdater.updateLicenses(); | ||
|
||
verify(licenseManager, times(0)).add(any(License.class)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters