Removing the API key while sharing or Cloudflare runs is allowed (the key is optional); the remove dialog warns plainly
This commit is contained in:
1 parent
bcf88b7383
commit
a4f7975324
2 files changed
+24
-1
No files matched your search
@@ -70,7 +70,7 @@ export function patch(body) {
|
||||
const s = getStore();
|
||||
const serving = { ...(s.serving ?? {}) };
|
||||
if (typeof body.otherDevices === 'boolean' && body.otherDevices !== !isLocal()) throw new Error('Change the host listen address and restart to update network access.');
|
||||
if (body.apiKey === null && (!isLocal() || sharing.active || tunnelActive())) throw new Error('Stop local sharing and Cloudflare before removing the API key.');
|
||||
// The key is optional (owner decision, 0.2.2): removing it while sharing or the tunnel runs is allowed; the app warns in plain words (local-share.mjs, cloudflare.mjs).
|
||||
if (body.apiKey === null) serving.apiKey = null;
|
||||
else if (typeof body.apiKey === 'string' && body.apiKey.trim()) serving.apiKey = body.apiKey.trim();
|
||||
else if (body.generateKey) serving.apiKey = `sk-strata-${randomBytes(12).toString('hex')}`;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/** The API key is optional (owner decision, 0.2.2): removing it while sharing or the Cloudflare tunnel runs is allowed, and the key stays removed. */
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const home = mkdtempSync(join(tmpdir(), 'strata-serving-key-'));
|
||||
process.env.STRATA_HOME = home;
|
||||
const serving = await import('../server/serving.mjs');
|
||||
|
||||
test('removing the API key while local sharing and the tunnel run is allowed', () => {
|
||||
serving.init({ send() {} }, { port: 8080, host: '127.0.0.1' });
|
||||
serving.patch({ generateKey: true });
|
||||
assert.equal(serving.state().access.apiKeySet, true);
|
||||
serving.setSharing({ active: true, url: 'http://192.168.1.5:8792/v1' });
|
||||
serving.setTunnel({ status: 'connected', mode: 'quick', url: 'https://example.trycloudflare.com', error: null, installed: true, originUrl: null });
|
||||
assert.equal(serving.state().access.otherDevices, true);
|
||||
const after = serving.patch({ apiKey: null });
|
||||
assert.equal(after.access.apiKeySet, false);
|
||||
assert.equal(serving.authorized({ headers: {} }), true);
|
||||
});
|
||||
test.after(() => { try { rmSync(home, { recursive: true, force: true }); } catch { /* temp folder */ } });
|
||||
Reference in new issue
Block a user