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 licensing test for expiring and expired licenses #2227

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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
24 changes: 17 additions & 7 deletions src/Frontend/src/components/configuration/PlatformLicense.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,44 @@ const configuration = useConfiguration();
<div class="box">
<div class="row">
<div class="license-info">
<div><b>Platform license type:</b> {{ typeText(license, configuration) }}{{ license.licenseEdition }}</div>
<div>
<b>Platform license type:</b> <span role="note" aria-label="license-type">{{ typeText(license, configuration) }}{{ license.licenseEdition }}</span>
</div>

<template v-if="licenseStatus.isSubscriptionLicense">
<div>
<b>License expiry date: </b>
<span
role="note"
aria-label="license-expiry-date"
:class="{
'license-expired': licenseStatus.isPlatformExpired,
}"
>
{{ license.formattedExpirationDate }}
{{ licenseStatus.subscriptionDaysLeft }}
<span role="note" aria-label="license-days-left">{{ licenseStatus.subscriptionDaysLeft }}</span>
<exclamation-mark :type="convertToWarningLevel(licenseStatus.warningLevel)" />
</span>
<div class="license-expired-text" v-if="licenseStatus.isPlatformExpired">Your license expired. Please update the license to continue using the Particular Service Platform.</div>
<div class="license-expired-text" role="note" aria-label="license-expired" v-if="licenseStatus.isPlatformExpired">Your license expired. Please update the license to continue using the Particular Service Platform.</div>
</div>
</template>
<template v-if="licenseStatus.isTrialLicense">
<div>
<b>License expiry date: </b>
<span
role="note"
aria-label="license-expiry-date"
:class="{
'license-expired': licenseStatus.isPlatformTrialExpired,
}"
>
{{ license.formattedExpirationDate }}
{{ licenseStatus.trialDaysLeft }}
<span role="note" aria-label="license-days-left"> {{ licenseStatus.trialDaysLeft }}</span>
<exclamation-mark :type="convertToWarningLevel(licenseStatus.warningLevel)" />
</span>
<div class="license-expired-text" v-if="licenseStatus.isPlatformTrialExpired">Your license expired. To continue using the Particular Service Platform you'll need to extend your license.</div>
<div class="license-expired-text" role="note" aria-label="license-expired" v-if="licenseStatus.isPlatformTrialExpired">
Your license expired. To continue using the Particular Service Platform you'll need to extend your license.
</div>
<div class="license-page-extend-trial" v-if="licenseStatus.isPlatformTrialExpiring && licenseStatus.isPlatformTrialExpired">
<a class="btn btn-default btn-primary" :href="license.license_extension_url" target="_blank">Extend your license&nbsp;&nbsp;<i class="fa fa-external-link"></i></a>
</div>
Expand All @@ -75,16 +83,18 @@ const configuration = useConfiguration();
<span>
<b>Upgrade protection expiry date:</b>
<span
role="note"
aria-label="license-expiry-date"
:class="{
'license-expired': licenseStatus.isInvalidDueToUpgradeProtectionExpired,
}"
>
{{ license.formattedUpgradeProtectionExpiration }}
{{ licenseStatus.upgradeDaysLeft }}
<span role="note" aria-label="license-days-left">{{ licenseStatus.upgradeDaysLeft }}</span>
<exclamation-mark :type="convertToWarningLevel(licenseStatus.warningLevel)" />
</span>
</span>
<div class="license-expired-text" v-if="licenseStatus.isValidWithExpiredUpgradeProtection || licenseStatus.isValidWithExpiringUpgradeProtection">
<div class="license-expired-text" role="note" aria-label="license-expired" v-if="licenseStatus.isValidWithExpiredUpgradeProtection || licenseStatus.isValidWithExpiringUpgradeProtection">
<b>Warning:</b> Once upgrade protection expires, you'll no longer have access to support or new product versions.
</div>
<div class="license-expired-text" v-if="licenseStatus.isInvalidDueToUpgradeProtectionExpired">Your license upgrade protection expired before this version of ServicePulse was released.</div>
Expand Down
5 changes: 5 additions & 0 deletions src/Frontend/src/resources/LicenseInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ export enum LicenseStatus {
ValidWithExpiringUpgradeProtection = "ValidWithExpiringUpgradeProtection",
ValidWithExpiringSubscription = "ValidWithExpiringSubscription",
}
export enum LicenseType {
Subscription,
Trial,
UpgradeProtection,
}
14 changes: 8 additions & 6 deletions src/Frontend/src/views/ConfigurationView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,37 @@ function preventIfDisabled(e: Event) {
<div class="row">
<div class="col-sm-12">
<div class="nav tabs">
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.license.link), disabled: notConnected }" @click.capture="preventIfDisabled" class="nav-item">
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.license.link), disabled: notConnected }" @click.capture="preventIfDisabled" class="nav-item" role="tab" aria-label="license">
<RouterLink :to="routeLinks.configuration.license.link">License</RouterLink>
<exclamation-mark :type="convertToWarningLevel(licenseStatus.warningLevel)" />
</h5>
<h5
:class="{ active: isRouteSelected(routeLinks.throughput.setup.root) || isRouteSelected(routeLinks.throughput.setup.mask.link) || isRouteSelected(routeLinks.throughput.setup.diagnostics.link), disabled: notConnected }"
@click.capture="preventIfDisabled"
class="nav-item"
role="tab"
aria-label="usage-setup"
>
<RouterLink :to="routeLinks.throughput.setup.root">Usage Setup</RouterLink>
<exclamation-mark :type="WarningLevel.Danger" v-if="hasErrors" />
</h5>
<template v-if="!licenseStatus.isExpired">
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.massTransitConnector.link), disabled: notConnected }" @click.capture="preventIfDisabled" class="nav-item">
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.massTransitConnector.link), disabled: notConnected }" @click.capture="preventIfDisabled" class="nav-item" role="tab" aria-label="mass-transit-connector">
<RouterLink :to="routeLinks.configuration.massTransitConnector.link">MassTransit Connector</RouterLink>
</h5>
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.healthCheckNotifications.link), disabled: notConnected }" @click.capture="preventIfDisabled" class="nav-item">
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.healthCheckNotifications.link), disabled: notConnected }" @click.capture="preventIfDisabled" class="nav-item" role="tab" aria-label="health-check-notifications">
<RouterLink :to="routeLinks.configuration.healthCheckNotifications.link">Health Check Notifications</RouterLink>
</h5>
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.retryRedirects.link), disabled: notConnected }" @click.capture="preventIfDisabled" class="nav-item">
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.retryRedirects.link), disabled: notConnected }" @click.capture="preventIfDisabled" class="nav-item" role="tab" aria-label="retry-redirects">
<RouterLink :to="routeLinks.configuration.retryRedirects.link">Retry Redirects ({{ redirectCount }})</RouterLink>
</h5>
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.connections.link) }" class="nav-item">
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.connections.link) }" class="nav-item" role="tab" aria-label="connections">
<RouterLink :to="routeLinks.configuration.connections.link">
Connections
<exclamation-mark v-if="displayConnectionsWarning" :type="WarningLevel.Danger" />
</RouterLink>
</h5>
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.endpointConnection.link), disabled: notConnected }" @click.capture="preventIfDisabled" class="nav-item">
<h5 :class="{ active: isRouteSelected(routeLinks.configuration.endpointConnection.link), disabled: notConnected }" @click.capture="preventIfDisabled" class="nav-item" role="tab" aria-label="endpoint-connection">
<RouterLink :to="routeLinks.configuration.endpointConnection.link">Endpoint Connection</RouterLink>
</h5>
</template>
Expand Down
13 changes: 0 additions & 13 deletions src/Frontend/test/mocks/license-response-template.ts

This file was deleted.

59 changes: 0 additions & 59 deletions src/Frontend/test/preconditions/hasLicense.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/Frontend/test/preconditions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "../preconditions/hasLicense";
export * from "../preconditions/licensing";
export { hasServiceControlMainInstance } from "../preconditions/hasServiceControlMainInstance";
export { hasServiceControlMonitoringInstance } from "../preconditions/hasServiceControlMonitoringInstance";
export { hasServiceControlMonitoringInstanceUrl } from "../preconditions/hasServiceControlMonitoringInstanceUrl";
Expand All @@ -15,6 +15,7 @@ export * from "./hasMonitoredEndpointDetails";
export { hasNoHeartbeatsEndpoints, hasHeartbeatsEndpoints } from "../preconditions/hasHeartbeatEndpoints";
export { serviceControlWithMonitoring } from "./serviceControlWithMonitoring";
export * from "./recoverability";
export * from "./licensing";
export { hasLicensingReportAvailable } from "../preconditions/hasLicensingReportAvailable";
export { hasLicensingSettingTest } from "../preconditions/hasLicensingSettingTest";
export { hasLicensingEndpoints } from "../preconditions/hasLicensingEndpoints";
Expand Down
90 changes: 90 additions & 0 deletions src/Frontend/test/preconditions/licensing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { SetupFactoryOptions } from "../driver";
import LicenseInfo, { LicenseStatus, LicenseType } from "@/resources/LicenseInfo";
import { useLicense } from "@/composables/serviceLicense";

const { license } = useLicense();
const licenseResponseTemplate = <LicenseInfo>{
registered_to: "ACME Software",
edition: "Enterprise",
expiration_date: "2026-01-23T00:00:00.0000000Z",
upgrade_protection_expiration: "",
license_type: "Commercial",
instance_name: "Particular.ServiceControl",
trial_license: false,
license_status: LicenseStatus.Valid,
license_extension_url: "",
status: "valid",
};
export const hasActiveLicense = ({ driver }: SetupFactoryOptions) => {
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
driver.mockEndpoint(`${serviceControlInstanceUrl}license`, {
body: licenseResponseTemplate,
});
return licenseResponseTemplate;
};
export const hasExpiredLicense = (licenseType: LicenseType, expiredDays: number = 10, extensionUrl: string = "") => getLicenseMockedResponse(licenseType, expiredDays, extensionUrl, true);
export const hasExpiringLicense = (licenseType: LicenseType, expiringInDays: number = 10, extensionUrl: string = "") => getLicenseMockedResponse(licenseType, expiringInDays, extensionUrl, false);

const getLicenseMockedResponse =
(licenseType: LicenseType, expiringInDays: number, extensionUrl: string, isExpired: boolean) =>
({ driver }: SetupFactoryOptions) => {
const serviceControlInstanceUrl = window.defaultConfig.service_control_url;
const customISOString = getCustomDateISOString(expiringInDays, isExpired);

let status: LicenseStatus;
let trialLicense = false;
let upgradeProtectionExpiration = "";
let expirationDate = "";
let licenseExtensionUrl = extensionUrl;

switch (licenseType) {
case LicenseType.Subscription:
status = isExpired ? LicenseStatus.InvalidDueToExpiredSubscription : LicenseStatus.ValidWithExpiringSubscription;
expirationDate = customISOString;
break;
case LicenseType.Trial:
status = isExpired ? LicenseStatus.InvalidDueToExpiredTrial : LicenseStatus.ValidWithExpiringTrial;
expirationDate = customISOString;
trialLicense = true;
licenseExtensionUrl = extensionUrl ? extensionUrl : "https://particular.net/extend-your-trial?p=servicepulse";
break;
case LicenseType.UpgradeProtection:
status = isExpired ? LicenseStatus.InvalidDueToExpiredUpgradeProtection : LicenseStatus.ValidWithExpiringUpgradeProtection;
upgradeProtectionExpiration = customISOString;
licenseExtensionUrl = extensionUrl ? extensionUrl : "https://particular.net/extend-your-trial?p=servicepulse";
break;
}

//We need to reset the global state to ensure the warning toast is always triggered by the value changing between multiple test runs. See documented issue and proposed solution https://github.com/Particular/ServicePulse/issues/1905
license.license_status = LicenseStatus.Unavailable;

const response = {
...licenseResponseTemplate,
license_type: status === LicenseStatus.ValidWithExpiringTrial || status === LicenseStatus.InvalidDueToExpiredTrial ? "Trial" : "Commercial",
trial_license: trialLicense,
expiration_date: expirationDate,
upgrade_protection_expiration: upgradeProtectionExpiration,
license_status: status,
license_extension_url: licenseExtensionUrl,
};
console.log(response);
driver.mockEndpoint(`${serviceControlInstanceUrl}license`, {
body: response,
});
return response;
};

function getCustomDateISOString(daysCount: number, isExpired: boolean) {
const today = new Date();
const customDate = new Date(today);

if (isExpired) {
customDate.setDate(today.getDate() - daysCount);
} else {
customDate.setDate(today.getDate() + daysCount);
}

const nativeISOString = customDate.toISOString(); // e.g., "2026-02-02T14:23:45.123Z"
const customISOString = nativeISOString.replace(/\.\d+Z$/, (match) => match.slice(0, -1).padEnd(8, "0") + "Z");
return customISOString;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { screen } from "@testing-library/vue";

export async function licenseExpired() {
const licenseExpiredText = await screen.findByRole("note", { name: "license-expired" });
return licenseExpiredText.textContent?.trim();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { screen } from "@testing-library/vue";

export async function licenseExpiryDate() {
const licenseExpiryDateElement = await screen.findByRole("note", { name: "license-expiry-date" });
return licenseExpiryDateElement;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { screen } from "@testing-library/vue";

export async function licenseExpiryDaysLeft() {
const licenseExpiryDaysLeftElement = await screen.findByRole("note", { name: "license-days-left" });
return licenseExpiryDaysLeftElement;
}
12 changes: 12 additions & 0 deletions src/Frontend/test/specs/configuration/questions/licenseTabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { screen } from "@testing-library/vue";

export async function licenseTabList() {
const tabs = await screen.findAllByRole("tab");
return tabs;
}
export async function licenseTabNames() {
const tabs = await screen.findAllByRole("tab");
// Check the names of the tabs
const tabNames = tabs.map((tab) => tab.textContent?.trim());
return tabNames;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { screen } from "@testing-library/vue";

export async function licenseTypeDetails() {
const licenseType = await screen.findByRole("note", { name: "license-type" });
return licenseType.textContent;
}
Loading
Loading