Skip to content

Commit

Permalink
fix: Reset the Premium Features flag before license checking
Browse files Browse the repository at this point in the history
The pre-compiled production bundle comes with true value of this flag always, because Vaadin CI server has a sub that enables it. Thus, Flow need to reset this flag before it calls the license server.
  • Loading branch information
mshabarov committed Sep 13, 2024
1 parent 5feb94b commit 5193d1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,12 @@ public static void updateBuildFile(PluginAdapterBuild adapter,
buildInfo.remove(Constants.CONNECT_OPEN_API_FILE_TOKEN);
buildInfo.remove(Constants.PROJECT_FRONTEND_GENERATED_DIR_TOKEN);
buildInfo.remove(InitParameters.BUILD_FOLDER);
// Premium features flag is always true, because Vaadin CI server
// uses Enterprise sub, thus it's always true.
// Thus, resets the premium feature flag before asking
// license-server
buildInfo.remove(Constants.PREMIUM_FEATURES);

buildInfo.put(SERVLET_PARAMETER_PRODUCTION_MODE, true);
buildInfo.put(APPLICATION_IDENTIFIER,
adapter.applicationIdentifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.vaadin.flow.server.ExecutionFailedException;
import com.vaadin.flow.server.InitParameters;
import com.vaadin.flow.server.frontend.EndpointGeneratorTaskFactory;
import com.vaadin.flow.server.frontend.FileIOUtils;
import com.vaadin.flow.server.frontend.FrontendTools;
import com.vaadin.flow.server.frontend.FrontendUtils;
import com.vaadin.flow.server.frontend.TaskGenerateEndpoint;
Expand All @@ -54,6 +55,7 @@

import elemental.json.Json;
import elemental.json.JsonObject;
import elemental.json.impl.JsonUtil;

import static com.vaadin.flow.server.frontend.FrontendUtils.FEATURE_FLAGS_FILE_NAME;
import static com.vaadin.flow.server.frontend.FrontendUtils.TOKEN_FILE;
Expand Down Expand Up @@ -417,6 +419,8 @@ public void updateBuildFile_tokenExisting_licenseRequiredAndIsPremiumLike_premiu
throws Exception {
File tokenFile = prepareAndAssertTokenFile();

addPremiumFeatureFlagTrue(tokenFile);

withMockedLicenseChecker(true, () -> {
BuildFrontendUtil.updateBuildFile(adapter, true);
Assert.assertTrue("Token file should still exist",
Expand All @@ -435,6 +439,8 @@ public void updateBuildFile_tokenExisting_licenseRequiredAndIsNotPremiumLike_pre
throws Exception {
File tokenFile = prepareAndAssertTokenFile();

addPremiumFeatureFlagTrue(tokenFile);

withMockedLicenseChecker(false, () -> {
BuildFrontendUtil.updateBuildFile(adapter, true);
Assert.assertTrue("Token file should still exist",
Expand Down Expand Up @@ -578,4 +584,16 @@ private void setupPluginAdapterDefaults() throws URISyntaxException {
this.getClass().getClassLoader()));
Mockito.when(adapter.runNpmInstall()).thenReturn(true);
}

private void addPremiumFeatureFlagTrue(File tokenFile) throws IOException {
// simulates true value placed into pre-compiled bundle
// when bundle is compiled on Vaadin CI server
String tokenJson = FileUtils.readFileToString(tokenFile,
StandardCharsets.UTF_8);
JsonObject buildInfo = JsonUtil.parse(tokenJson);
buildInfo.put(Constants.PREMIUM_FEATURES, true);

FileIOUtils.writeIfChanged(tokenFile,
JsonUtil.stringify(buildInfo, 2) + "\n");
}
}

0 comments on commit 5193d1b

Please sign in to comment.