/api/global/license/offline/identifier API

This commit is contained in:
Rory Powell 2023-07-08 13:07:10 +01:00
parent 9e1e869949
commit 90e869dc04
7 changed files with 44 additions and 3 deletions

View File

@ -17,3 +17,9 @@ export interface ActivateOfflineLicenseRequest {
export interface GetOfflineLicenseResponse { export interface GetOfflineLicenseResponse {
offlineLicenseToken: string offlineLicenseToken: string
} }
// IDENTIFIER
export interface GetOfflineIdentifierResponse {
identifierBase64: string
}

View File

@ -1,5 +1,15 @@
import { PurchasedPlan, Quotas, Feature, Billing } from "." import { PurchasedPlan, Quotas, Feature, Billing } from "."
export interface OfflineIdentifier {
installId: string,
tenantId: string
}
// export interface OfflineLicense extends License {
// identifier?: OfflineIdentifier
// identifierBase64: string
// }
export interface License { export interface License {
features: Feature[] features: Feature[]
quotas: Quotas quotas: Quotas

View File

@ -11,6 +11,7 @@ const pro = {
activateOfflineLicense: jest.fn(), activateOfflineLicense: jest.fn(),
getOfflineLicenseToken: jest.fn(), getOfflineLicenseToken: jest.fn(),
deleteOfflineLicenseToken: jest.fn(), deleteOfflineLicenseToken: jest.fn(),
getIdentifierBase64: jest.fn()
}, },
cache: { cache: {
...actual.licensing.cache, ...actual.licensing.cache,

View File

@ -3,6 +3,7 @@ import {
ActivateLicenseKeyRequest, ActivateLicenseKeyRequest,
ActivateOfflineLicenseRequest, ActivateOfflineLicenseRequest,
GetLicenseKeyResponse, GetLicenseKeyResponse,
GetOfflineIdentifierResponse,
GetOfflineLicenseResponse, GetOfflineLicenseResponse,
UserCtx, UserCtx,
} from "@budibase/types" } from "@budibase/types"
@ -53,6 +54,12 @@ export async function deleteOfflineLicense(ctx: UserCtx<void, void>) {
ctx.status = 204 ctx.status = 204
} }
export async function getOfflineLicenseIdentifier(ctx: UserCtx<void, GetOfflineIdentifierResponse>) {
const identifierBase64 = await licensing.offline.getIdentifierBase64()
ctx.body = { identifierBase64 }
ctx.status = 200
}
// LICENSES // LICENSES
export const refresh = async (ctx: any) => { export const refresh = async (ctx: any) => {

View File

@ -24,5 +24,6 @@ router
.post("/api/global/license/offline", activateOfflineLicenseValidator, controller.activateOfflineLicense) .post("/api/global/license/offline", activateOfflineLicenseValidator, controller.activateOfflineLicense)
.get("/api/global/license/offline", controller.getOfflineLicense) .get("/api/global/license/offline", controller.getOfflineLicense)
.delete("/api/global/license/offline", controller.deleteOfflineLicense) .delete("/api/global/license/offline", controller.deleteOfflineLicense)
.get("/api/global/license/offline/identifier", controller.getOfflineLicenseIdentifier)
export default router export default router

View File

@ -26,7 +26,7 @@ describe("/api/global/license", () => {
}) })
describe("GET /api/global/license/usage", () => { describe("GET /api/global/license/usage", () => {
it("returns 200", async () => { it("returns 200 + usage", async () => {
const usage = structures.quotas.usage() const usage = structures.quotas.usage()
quotas.getQuotaUsage.mockResolvedValue(usage) quotas.getQuotaUsage.mockResolvedValue(usage)
const res = await config.api.license.getUsage() const res = await config.api.license.getUsage()
@ -79,7 +79,7 @@ describe("/api/global/license", () => {
const res = await config.api.license.getOfflineLicense() const res = await config.api.license.getOfflineLicense()
expect(res.status).toBe(404) expect(res.status).toBe(404)
}) })
it("returns 200", async () => { it("returns 200 + offline license token", async () => {
licensing.offline.getOfflineLicenseToken.mockResolvedValue("offlineLicenseToken") licensing.offline.getOfflineLicenseToken.mockResolvedValue("offlineLicenseToken")
const res = await config.api.license.getOfflineLicense() const res = await config.api.license.getOfflineLicense()
expect(res.status).toBe(200) expect(res.status).toBe(200)
@ -90,10 +90,21 @@ describe("/api/global/license", () => {
}) })
describe("DELETE /api/global/license/offline", () => { describe("DELETE /api/global/license/offline", () => {
it("deletes offline license", async () => { it("returns 204", async () => {
const res = await config.api.license.deleteOfflineLicense() const res = await config.api.license.deleteOfflineLicense()
expect(res.status).toBe(204) expect(res.status).toBe(204)
expect(licensing.offline.deleteOfflineLicenseToken).toBeCalledTimes(1) expect(licensing.offline.deleteOfflineLicenseToken).toBeCalledTimes(1)
}) })
}) })
describe("GET /api/global/license/offline/identifier", () => {
it("returns 200 + identifier base64", async () => {
licensing.offline.getIdentifierBase64.mockResolvedValue("base64")
const res = await config.api.license.getOfflineLicenseIdentifier()
expect(res.status).toBe(200)
expect(res.body).toEqual({
identifierBase64: "base64"
})
})
})
}) })

View File

@ -51,4 +51,9 @@ export class LicenseAPI extends TestAPI {
.delete("/api/global/license/offline") .delete("/api/global/license/offline")
.set(this.config.defaultHeaders()) .set(this.config.defaultHeaders())
} }
getOfflineLicenseIdentifier = async () => {
return this.request
.get("/api/global/license/offline/identifier")
.set(this.config.defaultHeaders())
}
} }