Makelore 2.0 initial clean snapshot
This commit is contained in:
51
tests/unit/meowa-game-assets-release-credential.test.ts
Normal file
51
tests/unit/meowa-game-assets-release-credential.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import {
|
||||
getMeowaReleaseCredentialPath,
|
||||
MEOWA_RELEASE_CREDENTIAL_FILE_NAME,
|
||||
readBundledMeowaApiKey,
|
||||
readEmbeddedMeowaApiKey,
|
||||
} from '@electron/services/meowa-game-assets-release-credential';
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
|
||||
});
|
||||
|
||||
describe('Meowa release credential resource', () => {
|
||||
it('provides the approved Main-only embedded credential', () => {
|
||||
const apiKey = readEmbeddedMeowaApiKey();
|
||||
expect(apiKey).toMatch(/^ma_live_/);
|
||||
expect(apiKey?.length).toBeLessThanOrEqual(512);
|
||||
});
|
||||
|
||||
it('reads a versioned packaged credential from the resources tree', async () => {
|
||||
const resourcesPath = await mkdtemp(join(tmpdir(), 'niancode-meowa-release-'));
|
||||
tempDirs.push(resourcesPath);
|
||||
const file = getMeowaReleaseCredentialPath(resourcesPath);
|
||||
await mkdir(join(resourcesPath, 'resources'), { recursive: true });
|
||||
await writeFile(file, JSON.stringify({ schemaVersion: 1, apiKey: 'release-secret' }), 'utf8');
|
||||
|
||||
await expect(readBundledMeowaApiKey(resourcesPath)).resolves.toBe('release-secret');
|
||||
expect(file.endsWith(MEOWA_RELEASE_CREDENTIAL_FILE_NAME)).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects malformed, unversioned, and oversized packaged credentials', async () => {
|
||||
const resourcesPath = await mkdtemp(join(tmpdir(), 'niancode-meowa-release-'));
|
||||
tempDirs.push(resourcesPath);
|
||||
const file = getMeowaReleaseCredentialPath(resourcesPath);
|
||||
await mkdir(join(resourcesPath, 'resources'), { recursive: true });
|
||||
|
||||
await writeFile(file, JSON.stringify({ apiKey: 'missing-version' }), 'utf8');
|
||||
await expect(readBundledMeowaApiKey(resourcesPath)).resolves.toBeNull();
|
||||
|
||||
await writeFile(file, '{not-json', 'utf8');
|
||||
await expect(readBundledMeowaApiKey(resourcesPath)).resolves.toBeNull();
|
||||
|
||||
await writeFile(file, JSON.stringify({ schemaVersion: 1, apiKey: 'x'.repeat(513) }), 'utf8');
|
||||
await expect(readBundledMeowaApiKey(resourcesPath)).resolves.toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user