diff --git a/src/routes/list.js b/src/routes/list.js index dc4ddfb0..f1ee1f4d 100644 --- a/src/routes/list.js +++ b/src/routes/list.js @@ -9,12 +9,11 @@ * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ -import listBuckets from '../storage/bucket/list.js'; import listObjects from '../storage/object/list.js'; import { getChildRules, hasPermission } from '../utils/auth.js'; export default async function getList({ env, daCtx }) { - if (!daCtx.org) return listBuckets(env, daCtx); + if (!daCtx.org) return { status: 404 }; if (!hasPermission(daCtx, daCtx.key, 'read')) return { status: 403 }; // Get the child rules of the current folder and store this in daCtx.aclCtx diff --git a/src/storage/bucket/list.js b/src/storage/bucket/list.js deleted file mode 100644 index 731b2e59..00000000 --- a/src/storage/bucket/list.js +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2024 Adobe. All rights reserved. - * This file is licensed to you under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy - * of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - * OF ANY KIND, either express or implied. See the License for the specific language - * governing permissions and limitations under the License. - */ -import { hasPermission } from '../../utils/auth.js'; - -async function isBucketAuthed(env, daCtx, bucket) { - const { name, created } = bucket; - - if (!hasPermission(daCtx, name, 'read')) { - return null; - } - return { name, created }; -} - -async function formatBuckets(env, daCtx, buckets) { - const authResults = await Promise.all( - buckets.map((bucket) => isBucketAuthed(env, daCtx, bucket)), - ); - return authResults.filter((res) => res); -} - -export default async function listBuckets(env, daCtx) { - try { - const orgs = await env.DA_AUTH.get('orgs', { type: 'json' }); - const body = await formatBuckets(env, daCtx, orgs); - - return { - body: JSON.stringify(body), - status: 200, - contentType: 'application/json', - }; - } catch (e) { - return { body: '', status: 404 }; - } -} diff --git a/test/routes/list.test.js b/test/routes/list.test.js index 99751653..c7bdfe1f 100644 --- a/test/routes/list.test.js +++ b/test/routes/list.test.js @@ -51,4 +51,11 @@ describe('List Route', () => { assert.strictEqual(1, childRules.length); assert(childRules[0].startsWith('/q/q/**='), 'Should have defined some child rule'); }); + + it('returns 404 when no org is present', async () => { + const getList = await import('../../src/routes/list.js'); + + const res = await getList.default({ env: {}, daCtx: {}, aclCtx: {} }); + assert.strictEqual(404, res.status); + }) }); diff --git a/test/storage/bucket/list.test.js b/test/storage/bucket/list.test.js deleted file mode 100644 index cfab8252..00000000 --- a/test/storage/bucket/list.test.js +++ /dev/null @@ -1,28 +0,0 @@ -import assert from 'assert'; -import listBuckets from '../../../src/storage/bucket/list.js'; -import env from './mocks/env.js'; - -describe('List', () => { - const aclCtx = { - pathLookup: new Map() - }; - const daCtx = { users: [{email: 'aparker@geometrixx.info'}], aclCtx }; - - /* This test has to be rewritten - describe('Lists authed buckets', async () => { - const bucketsResp = await listBuckets(env, daCtx); - const buckets = JSON.parse(bucketsResp.body); - - it('Only authed and anon buckets are listed', () => { - assert.strictEqual(buckets.length, 2); - }); - }); - */ - - describe('404s on any error', () => { - it('Dies on null env', async () => { - const bucketsResp = await listBuckets(null, daCtx); - assert.strictEqual(bucketsResp.status, 404); - }); - }); -}); diff --git a/test/storage/bucket/mocks/env.js b/test/storage/bucket/mocks/env.js deleted file mode 100644 index 7cacc1b0..00000000 --- a/test/storage/bucket/mocks/env.js +++ /dev/null @@ -1,59 +0,0 @@ -const NAMESPACES = { - orgs: [ - { - "name": "adobe", - "created": "2024-01-09T23:38:05.949Z" - }, - { - "name": "geometrixx", - "created": "2023-11-30T06:04:10.008Z" - }, - { - "name": "wknd", - "created": "2023-11-30T06:04:10.008Z" - } - ], -}; -const DA_CONFIG = { - geometrixx: { - "total": 1, - "limit": 1, - "offset": 0, - "data": [ - { - "key": "admin.role.all", - "value": "aparker@geometrixx.info" - } - ], - ":type": "sheet" - }, - adobe: { - "total": 1, - "limit": 1, - "offset": 0, - "data": [ - { - "key": "admin.role.all", - "value": "notyou@you.com" - } - ], - ":type": "sheet" - } -}; - -const env = { - DA_AUTH: { - get: (kvNamespace) => { - return NAMESPACES[kvNamespace]; - } - }, - DA_CONFIG: { - get: (name) => { - const nameConfig = DA_CONFIG[name]; - console.log(nameConfig); - return nameConfig; - } - } -}; - -export default env;