Skip to content

Commit

Permalink
fix(cli): add test to authorize gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Dec 12, 2024
1 parent 4c03d6d commit 6849fa4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ cli
.option('-ag, --authorize-gateway-services <json>', '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)
}
}

Expand All @@ -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)
})
Expand Down
37 changes: 37 additions & 0 deletions packages/cli/test/bin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,43 @@ export const testSpace = {
assert.match(error, /wait.*plan.*select/i)
}),

'storacha space create home --no-recovery --customer [email protected] --account [email protected] --authorize-gateway-services':
test(async (assert, context) => {
const email = '[email protected]'
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

Expand Down

0 comments on commit 6849fa4

Please sign in to comment.