Skip to content

Commit

Permalink
feat: enable tenant check on AMT operations
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdmike committed Sep 21, 2023
1 parent 984e1af commit 49101a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/middleware/cira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ const ciraMiddleware = async (req: Request, res: Response, next): Promise<void>
const device = devices[guid]

if ((device as any)?.ciraSocket.readyState === 'open') {
// const cred = await req.mpsService.secrets.getAMTCredentials(guid);
// req.amtStack = req.amtFactory.getAmtStack(guid, amtPort, cred[0], cred[1], 0)
// (req as any).httpHandler = new HttpHandler(cred[0], cred[1])
// if a tenantId is provided, ensure the request is for the same tenant/device
if (req.tenantId != null) {
if (req.tenantId !== device.tenantId) {
res.status(401).json(ErrorResponse(401, 'Unauthorized')).end()
return

Check warning on line 24 in src/middleware/cira.ts

View check run for this annotation

Codecov / codecov/patch

src/middleware/cira.ts#L23-L24

Added lines #L23 - L24 were not covered by tests
}
}

const ciraHandler = new CIRAHandler(device.httpHandler, device.username, device.password, device.limiter)
req.deviceAction = new DeviceAction(ciraHandler, device.ciraSocket)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const UUIDRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA
export const HTTPErrorTable = {
200: 'httpErrorTableOK',
400: 'Incorrect URI or Bad Request',
401: 'Authentication Error',
401: 'Unauthorized',
404: {
alarm: 'Alarm instance not found',
device: 'Device not found/connected. Please connect again using CIRA.',
Expand Down

0 comments on commit 49101a7

Please sign in to comment.