diff --git a/packages/cli/bin.js b/packages/cli/bin.js index 2a434738c..c19da5acd 100755 --- a/packages/cli/bin.js +++ b/packages/cli/bin.js @@ -135,13 +135,13 @@ cli .option('-ag, --authorize-gateway-services ', 'Authorize Gateways to serve the content uploaded to this space, e.g: \'[{"id":"did:key:z6Mki...","serviceEndpoint":"https://gateway.example.com"}]\'') .option('-nga, --no-gateway-authorization', 'Skip Gateway Authorization') .action((name, options) => { - let authorizeGatewayServices = []; + let authorizeGatewayServices = [] if (options['authorize-gateway-services']) { try { - authorizeGatewayServices = JSON.parse(options['authorize-gateway-services']); + authorizeGatewayServices = JSON.parse(options['authorize-gateway-services']) } catch (err) { - console.error('Invalid JSON format for --authorize-gateway-services'); - process.exit(1); + console.error('Invalid JSON format for --authorize-gateway-services') + process.exit(1) } } @@ -151,7 +151,7 @@ cli skipGatewayAuthorization: options['gateway-authorization'] === false || options['gateway-authorization'] === undefined, // default to empty array if not set, so the client will validate the gateway services authorizeGatewayServices: authorizeGatewayServices || [], - }; + } return Space.create(name, parsedOptions) }) diff --git a/packages/cli/test/bin.spec.js b/packages/cli/test/bin.spec.js index 25dcf514b..6728cdcd3 100644 --- a/packages/cli/test/bin.spec.js +++ b/packages/cli/test/bin.spec.js @@ -320,6 +320,43 @@ export const testSpace = { assert.match(error, /wait.*plan.*select/i) }), + 'storacha space create home --no-recovery --customer alice@web.mail --account alice@web.mail --authorize-gateway-services': + test(async (assert, context) => { + const email = 'alice@web.mail' + await login(context, { email }) + await selectPlan(context, { email }) + + const serverId = context.connection.id + const serverURL = context.serverURL + + const { output } = await storacha + .args([ + 'space', + 'create', + 'home', + '--no-recovery', + '--customer', + email, + '--account', + email, + '--authorize-gateway-services', + `[{"id":"${serverId}","serviceEndpoint":"${serverURL}"}]`, + ]) + .env(context.env.alice) + .join() + + assert.match(output, /account is authorized/i) + + const result = await context.delegationsStorage.find({ + audience: DIDMailto.fromEmail(email), + }) + + assert.ok( + result.ok?.find((d) => d.capabilities[0].can === '*'), + 'account has been delegated access to the space' + ) + }), + 'storacha space add': test(async (assert, context) => { const { env } = context