mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-12 03:36:59 +00:00
865d792874
* feat(pricing): collapse to two tiers (Community + Admiral) Collapse Sencho's pricing from three tiers (Community / Skipper / Admiral) to two: a generous free Community tier and a single paid Admiral tier. The Skipper tier is removed. Now free in Community: auto-heal, auto-update, scheduled operations, webhooks, notification routing, Fleet Actions and bulk operations, SSO preset providers (Google / GitHub / Okta), unlimited users with admin and viewer roles, and deploy safety (atomic deploys, auto-rollback, and one-click rollback). Admiral (paid) is focused on running and governing a fleet: blueprints, Fleet Secrets, deploy enforcement, vulnerability report export, audit log, host console, private registries, mesh networking, node cordon, managed cloud backup, LDAP / Active Directory SSO, and the advanced RBAC roles (deployer, node-admin, auditor) with per-resource scoped assignments. Internally the license variant distinction is removed so tier is binary (community / paid). License validation still verifies the Lemon Squeezy store and product before granting paid status. Docs and the contributor guide are updated to the two-tier model. * docs(pricing): correct licensing page to two-tier pricing and tidy stale tier wording The licensing docs page kept the old Admiral pricing plus a Founder Lifetime column and an Enterprise paragraph after the two-tier collapse. Update it to $12/month or $99/year, drop the lifetime and Enterprise content, and link to the pricing page for current pricing. Also fix stale "Skipper" wording in CLA.md, SUPPORT.md, one test title, and three test comments. Historical CHANGELOG entries and the retired-Skipper license-guard test are intentionally left as-is. * docs: align licensing and SSO pages with the two-tier model Correct the SSO overview so the Google, GitHub, and Okta presets read as available on every tier, matching the provider table; only LDAP and Active Directory require Sencho Admiral. Remove the lifetime-plan references from the licensing, settings, and troubleshooting pages so they reflect subscription-only Admiral pricing. * fix(rbac): omit scoped permissions from /me on the Community tier Scoped role assignments only take effect on the paid tier, but GET /api/permissions/me returned them unconditionally, so a downgraded instance with leftover assignments rendered per-resource affordances the API then rejected with 403. The endpoint now mirrors the permission middleware and includes scoped permissions only on the paid tier. Adds a regression test covering the downgrade case. * docs: use custom-pricing wording on the contact page The two-tier model has no Enterprise tier; reword the contact page's enterprise pricing/deals to custom pricing/deals so it does not imply a tier that no longer exists.
161 lines
6.0 KiB
TypeScript
161 lines
6.0 KiB
TypeScript
/**
|
|
* Tests for Distributed License Enforcement: the trust chain where the main
|
|
* instance asserts its license tier to remote nodes via proxy headers.
|
|
*/
|
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
import request from 'supertest';
|
|
import jwt from 'jsonwebtoken';
|
|
import { setupTestDb, cleanupTestDb, TEST_USERNAME, TEST_JWT_SECRET } from './helpers/setupTestDb';
|
|
|
|
let tmpDir: string;
|
|
let app: import('express').Express;
|
|
|
|
beforeAll(async () => {
|
|
tmpDir = await setupTestDb();
|
|
({ app } = await import('../index'));
|
|
});
|
|
|
|
afterAll(() => {
|
|
cleanupTestDb(tmpDir);
|
|
});
|
|
|
|
/** Helper: sign a token with the test JWT secret. */
|
|
const signToken = (payload: Record<string, unknown>, expiresIn: string | number = '1m') =>
|
|
jwt.sign(payload, TEST_JWT_SECRET, { expiresIn: expiresIn as jwt.SignOptions['expiresIn'] });
|
|
|
|
// We need a Paid-gated route that doesn't depend on Docker or remote nodes.
|
|
// /api/webhooks/... triggers are public, but the management routes are
|
|
// admin-gated, so we use a Paid-gated route that just reads from the DB.
|
|
// /api/audit-log is paid-gated and reads from the DB.
|
|
const PAID_ROUTE = '/api/audit-log';
|
|
|
|
// ─── authMiddleware: proxyTier propagation ──────────────────────────────────
|
|
|
|
describe('authMiddleware - distributed license headers', () => {
|
|
it('sets proxyTier for node_proxy tokens with a valid tier header', async () => {
|
|
const token = signToken({ scope: 'node_proxy' });
|
|
// Hit a Paid-gated route with tier assertion - should be allowed
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.set('x-sencho-tier', 'paid');
|
|
|
|
// Should NOT get 403 PAID_REQUIRED; the proxy tier assertion grants access
|
|
expect(res.status).not.toBe(403);
|
|
});
|
|
|
|
it('ignores tier headers for user session tokens', async () => {
|
|
const token = signToken({ username: TEST_USERNAME, role: 'admin' });
|
|
// Even with a tier header set, a user session should use the local license (community)
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.set('x-sencho-tier', 'paid');
|
|
|
|
// Local license is community in test env → should get 403
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.code).toBe('PAID_REQUIRED');
|
|
});
|
|
|
|
it('ignores tier headers for malformed values on node_proxy tokens', async () => {
|
|
const token = signToken({ scope: 'node_proxy' });
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.set('x-sencho-tier', 'enterprise'); // invalid value
|
|
|
|
// Invalid tier header → proxyTier not set → falls back to local (community) → 403
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.code).toBe('PAID_REQUIRED');
|
|
});
|
|
|
|
it('falls back to local tier when no tier headers on node_proxy token', async () => {
|
|
const token = signToken({ scope: 'node_proxy' });
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('Authorization', `Bearer ${token}`);
|
|
// No tier headers → falls back to local (community) → 403
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.code).toBe('PAID_REQUIRED');
|
|
});
|
|
});
|
|
|
|
// ─── requirePaid guard ───────────────────────────────────────────────────────
|
|
|
|
describe('requirePaid - distributed license', () => {
|
|
it('allows access when proxy asserts paid tier', async () => {
|
|
const token = signToken({ scope: 'node_proxy' });
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.set('x-sencho-tier', 'paid');
|
|
|
|
expect(res.status).not.toBe(403);
|
|
});
|
|
|
|
it('blocks access when proxy asserts community tier', async () => {
|
|
const token = signToken({ scope: 'node_proxy' });
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.set('x-sencho-tier', 'community');
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.code).toBe('PAID_REQUIRED');
|
|
});
|
|
|
|
it('blocks access for direct user when local tier is community', async () => {
|
|
const token = signToken({ username: TEST_USERNAME, role: 'admin' });
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('Authorization', `Bearer ${token}`);
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.code).toBe('PAID_REQUIRED');
|
|
});
|
|
});
|
|
|
|
// ─── Security: header injection prevention ──────────────────────────────────
|
|
|
|
describe('Security - tier header injection', () => {
|
|
it('cannot elevate access via tier headers on a user session', async () => {
|
|
const token = signToken({ username: TEST_USERNAME, role: 'admin' });
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.set('x-sencho-tier', 'paid');
|
|
|
|
// User session → tier headers ignored → local community tier → 403
|
|
expect(res.status).toBe(403);
|
|
});
|
|
|
|
it('cannot elevate access via tier headers without any auth', async () => {
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('x-sencho-tier', 'paid');
|
|
|
|
expect(res.status).toBe(401);
|
|
});
|
|
|
|
it('cannot elevate access with expired node_proxy token', async () => {
|
|
const token = jwt.sign({ scope: 'node_proxy' }, TEST_JWT_SECRET, { expiresIn: '-1s' });
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.set('x-sencho-tier', 'paid');
|
|
|
|
expect(res.status).toBe(401);
|
|
});
|
|
|
|
it('cannot elevate access with token signed by wrong secret', async () => {
|
|
const token = jwt.sign({ scope: 'node_proxy' }, 'wrong-secret', { expiresIn: '1m' });
|
|
const res = await request(app)
|
|
.get(PAID_ROUTE)
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.set('x-sencho-tier', 'paid');
|
|
|
|
expect(res.status).toBe(401);
|
|
});
|
|
});
|