Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions components/console/src/pages/Backbones/BackboneDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const BackboneDetail = () => {
return () => {
CancelWatch(watchContext);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [backboneId]);

return (
Expand Down Expand Up @@ -83,7 +82,6 @@ const BackboneDetail = () => {
{!loading && !error && viewMode === 'list' && (
<BackboneListView
sites={sites}
backboneName={backboneName}
backboneId={backboneId}
backboneOwnerGroup={backboneOwnerGroup}
/>
Expand Down
3 changes: 1 addition & 2 deletions components/console/src/pages/Backbones/BackboneListView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import SiteDeployment from './SiteDeployment';

const BackboneListView = ({
sites,
backboneName,
backboneId,
backboneOwnerGroup = '',
}) => {
Expand Down Expand Up @@ -515,4 +514,4 @@ const BackboneListView = ({

export default BackboneListView;

// Made with Bob
// Made with Bob
10 changes: 4 additions & 6 deletions components/console/src/pages/Backbones/SiteDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const SiteDetail = () => {
if (errorBody) {
errorMessage = errorBody;
}
} catch (e) {
} catch {
// If we can't read the body, use the default error message
}
throw new Error(errorMessage);
Expand Down Expand Up @@ -311,7 +311,7 @@ const SiteDetail = () => {
if (errorBody) {
errorMessage = errorBody;
}
} catch (e) {
} catch {
// If we can't read the body, use the default error message
}
throw new Error(errorMessage);
Expand Down Expand Up @@ -385,7 +385,7 @@ const SiteDetail = () => {
if (errorBody) {
errorMessage = errorBody;
}
} catch (e) {
} catch {
// If we can't read the body, use the default error message
}
throw new Error(errorMessage);
Expand Down Expand Up @@ -464,8 +464,6 @@ const SiteDetail = () => {
case 'error':
type = 'red';
break;
default:
type = 'gray';
}
return {
text: lifecycle,
Expand Down Expand Up @@ -1024,4 +1022,4 @@ const SiteDetail = () => {

export default SiteDetail;

// Made with Bob
// Made with Bob
4 changes: 2 additions & 2 deletions components/console/src/pages/VANs/VANs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const VANs = () => {
if (errorBody) {
errorMessage = errorBody;
}
} catch (e) {
} catch {
// If we can't read the body, use the default error message
}
throw new Error(errorMessage);
Expand Down Expand Up @@ -211,7 +211,7 @@ const VANs = () => {
setExposeNetworkObserver(false);

// Fetch access points of type "van" from the VAN's backbone
let backbone = (van.backbone) ? van.backbone : selectedBackbone;
const backbone = (van.backbone) ? van.backbone : selectedBackbone;
if (backbone) {
try {
setLoadingAccessPoints(true);
Expand Down
51 changes: 22 additions & 29 deletions components/management-controller/src/api-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const createBackbone = async function(req, res) {
let returnStatus;
const form = new IncomingForm();
try {
const [fields, files] = await form.parse(req);
const [fields] = await form.parse(req);
const norm = ValidateAndNormalizeFields(fields, {
'name' : {type: 'dns-segment', optional: false},
'ownerGroup': {type: 'string', optional: true, default: ''},
Expand All @@ -44,7 +44,6 @@ const createBackbone = async function(req, res) {
const notify = new NotifyTransaction();
try {
let backboneId;
let siteId;
await queryWithContext(req, client, async (client, userInfo) => {
const result = await client.query(
"INSERT INTO Backbones(Name, LifeCycle, Owner, OwnerGroup, CoLocatedNamespace) " +
Expand Down Expand Up @@ -79,7 +78,7 @@ const createBackboneSite = async function(req, res) {
throw new Error('Backbone-Id is not a valid uuid');
}

const [fields, files] = await form.parse(req)
const [fields] = await form.parse(req)
const norm = ValidateAndNormalizeFields(fields, {
'name' : {type: 'dnsname', optional: false},
'platform' : {type: 'dnsname', optional: false},
Expand All @@ -99,7 +98,7 @@ const createBackboneSite = async function(req, res) {
//
const namesResult = await client.query("SELECT Name FROM InteriorSites WHERE Backbone = $1", [bid]);

let existingNames = [];
const existingNames = [];
for (const row of namesResult.rows) {
existingNames.push(row.name);
}
Expand Down Expand Up @@ -149,10 +148,10 @@ const updateBackboneSite = async function(req, res) {
const form = new IncomingForm();
try {
if (!IsValidUuid(sid)) {
throw(Error('Site-Id is not a valid uuid'));
throw new Error('Site-Id is not a valid uuid');
}

const [fields, files] = await form.parse(req);
const [fields] = await form.parse(req);
const norm = ValidateAndNormalizeFields(fields, {
'name' : {type: 'string', optional: true, default: null},
'metadata' : {type: 'string', optional: true, default: null},
Expand All @@ -161,14 +160,10 @@ const updateBackboneSite = async function(req, res) {
const client = await ClientFromPool();
const notify = new NotifyTransaction();
try {
let nameChanged = false;

await queryWithContext(req, client, async (client) => {
const siteResult = await client.query("SELECT * FROM InteriorSites WHERE Id = $1", [sid]);
if (siteResult.rowCount == 1) {
const site = siteResult.rows[0];
let siteName = site.name;

//
// If InteriorSite is CoLocated, no changes are allowed
//
Expand All @@ -180,9 +175,7 @@ const updateBackboneSite = async function(req, res) {
// If the name has been changed, update the site record in the database
//
if (norm.name != null && norm.name != site.name) {
nameChanged = true;
await client.query("UPDATE InteriorSites SET Name = $1 WHERE Id = $2", [norm.name, sid]);
siteName = norm.name;
}

//
Expand Down Expand Up @@ -213,15 +206,15 @@ const updateBackboneSite = async function(req, res) {
}

const createAccessPoint = async function(req, res) {
var returnStatus;
let returnStatus;
const sid = req.params.sid;
const form = new IncomingForm();
try {
if (!IsValidUuid(sid)) {
throw(Error('Site-Id is not a valid uuid'));
throw new Error('Site-Id is not a valid uuid');
}

const [fields, files] = await form.parse(req)
const [fields] = await form.parse(req)
const norm = ValidateAndNormalizeFields(fields, {
'name' : {type: 'dnsname', optional: true, default: null},
'kind' : {type: 'accesskind', optional: false},
Expand Down Expand Up @@ -301,15 +294,15 @@ const createAccessPoint = async function(req, res) {
}

const createBackboneLink = async function(req, res) {
var returnStatus;
let returnStatus;
const apid = req.params.apid;
const form = new IncomingForm();
try {
if (!IsValidUuid(apid)) {
throw new Error('AccessPoint-Id is not a valid uuid');
}

const [fields, files] = await form.parse(req);
const [fields] = await form.parse(req);
const norm = ValidateAndNormalizeFields(fields, {
'connectingsite' : {type: 'uuid', optional: false},
'cost' : {type: 'number', optional: true, default: 1},
Expand All @@ -332,27 +325,27 @@ const createBackboneLink = async function(req, res) {
// Validate that the referenced access point exists
//
if (accessResult.rowCount == 0) {
throw(Error(`Referenced access point not found: ${apid}`));
throw new Error(`Referenced access point not found: ${apid}`);
}
const accessPoint = accessResult.rows[0];

//
// Validate that the referenced access point is of kind 'peer'
//
if (accessPoint.kind != 'peer') {
throw(Error(`Referenced access point must be 'peer', found '${accessPoint.kind}'`));
throw new Error(`Referenced access point must be 'peer', found '${accessPoint.kind}'`);
}

//
// Validate that the referenced site is in the specified backbone network
//
const siteResult = await client.query("SELECT Backbone FROM InteriorSites WHERE Id = $1", [norm.connectingsite]);
if (siteResult.rowCount == 0) {
throw(Error(`Referenced connecting site not found: ${norm.connectingsite}`));
throw new Error(`Referenced connecting site not found: ${norm.connectingsite}`);
}

if (siteResult.rows[0].backbone != accessPoint.backbone) {
throw(Error(`Referenced connecting site is not in the same backbone network as the access-point`));
throw new Error(`Referenced connecting site is not in the same backbone network as the access-point`);
}

//
Expand Down Expand Up @@ -397,15 +390,15 @@ const createBackboneLink = async function(req, res) {
}

const updateBackboneLink = async function(req, res) {
var returnStatus = 204;
let returnStatus = 204;
const lid = req.params.lid;
const form = new IncomingForm();
try {
if (!IsValidUuid(lid)) {
throw(Error('Link-Id is not a valid uuid'));
throw new Error('Link-Id is not a valid uuid');
}

const [fields, files] = await form.parse(req);
const [fields] = await form.parse(req);
const norm = ValidateAndNormalizeFields(fields, {
'cost' : {type: 'number', optional: true, default: null},
});
Expand Down Expand Up @@ -479,7 +472,7 @@ const deleteBackbone = async function(req, res) {
const colo = coloResult.rows[0];
notify.delete('InteriorSites', colo.id);
}
const bbResult = await client.query("DELETE FROM Backbones WHERE Id = $1 RETURNING Certificate", [bid]);
await client.query("DELETE FROM Backbones WHERE Id = $1 RETURNING Certificate", [bid]);
notify.delete('Backbones', bid);
});
res.status(returnStatus).end();
Expand Down Expand Up @@ -565,10 +558,10 @@ const deleteBackboneSite = async function(req, res) {
}

const deleteAccessPoint = async function(req, res) {
var returnStatus = 204;
let returnStatus = 204;
const apid = req.params.apid;
var siteId = undefined;
var wasManage = false;
let siteId;
let wasManage = false;
const client = await ClientFromPool();
const notify = new NotifyTransaction();
try {
Expand Down Expand Up @@ -922,7 +915,7 @@ const listSiteIngresses = async function(req, res) {
}

const listInvitations = async function(req, res) {
let returnStatus = 200;
const returnStatus = 200;
const client = await ClientFromPool();

const result = await queryWithContext(req, client, async (client) => {
Expand Down
18 changes: 10 additions & 8 deletions components/management-controller/src/api-admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ vi.mock('./db.js', async (importOriginal) => {
describe('api-admin', () => {
beforeEach(() => {
vi.clearAllMocks();
mockClient.query.mockImplementation(async (sql, params) => {
mockClient.query.mockImplementation(async (sql) => {
if (sql === 'BEGIN' || sql === 'COMMIT' || sql === 'ROLLBACK') {
return {};
}
Expand Down Expand Up @@ -139,9 +139,10 @@ describe('api-admin', () => {
it('GET /backbones returns 401 without authentication', async () => {
const { app } = await buildApiApp({ includeUser: false });

await request(app)
.get('/api/v1alpha1/backbones')
.expect(401);
const res = await request(app)
.get('/api/v1alpha1/backbones');

expect(res.status).toBe(401);
});

it('GET /backbones returns 403 without list role', async () => {
Expand All @@ -150,15 +151,16 @@ describe('api-admin', () => {
roles: ['viewer'],
});

await request(app)
const res = await request(app)
.get('/api/v1alpha1/backbones')
.set('x-test-auth', '1')
.expect(403);
.set('x-test-auth', '1');

expect(res.status).toBe(403);
});

it('POST /backbones creates a backbone', async () => {
mockFormFields = { name: 'new-backbone' };
mockClient.query.mockImplementation(async (sql, params) => {
mockClient.query.mockImplementation(async (sql) => {
if (sql === 'BEGIN' || sql === 'COMMIT' || sql === 'ROLLBACK') {
return {};
}
Expand Down
Loading