-
Notifications
You must be signed in to change notification settings - Fork 394
Add MSP360 Backup and RMM integrations #3559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tonyzorin
wants to merge
5
commits into
trycompai:main
Choose a base branch
from
tonyzorin:feat/msp360-backup-rmm-integrations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9fb39f3
Add MSP360 Backup and RMM Comp AI integration manifests.
tonyzorin f090bb8
Harden MSP360 Backup and RMM checks against live APIs.
tonyzorin 932d3ed
Fix Cubic review findings on MSP360 Backup and RMM evidence.
tonyzorin b00afb5
Treat unknown in-window restores as failed and probe past the RMM pag…
tonyzorin 154c32b
Pass the effective RMM page cap into truncation findings.
tonyzorin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
289 changes: 289 additions & 0 deletions
289
packages/integration-platform/src/manifests/msp360-backup/__tests__/checks.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,289 @@ | ||
| import { describe, expect, it } from 'bun:test'; | ||
| import { appAvailabilityCheck } from '../checks/app-availability'; | ||
| import { backupLogsCheck } from '../checks/backup-logs'; | ||
| import { backupRestorationTestCheck } from '../checks/backup-restoration-test'; | ||
| import { employeeAccessCheck } from '../checks/employee-access'; | ||
| import { makeBackupCtx } from './test-utils'; | ||
|
|
||
| const TOKEN = { access_token: 'backup-jwt' }; | ||
|
|
||
| function router(path: string, method: string | undefined, handlers: Record<string, unknown>) { | ||
| if (path.includes('/Provider/Login') && method === 'POST') { | ||
| return TOKEN; | ||
| } | ||
| for (const [key, value] of Object.entries(handlers)) { | ||
| if (path.includes(key)) { | ||
| if (value instanceof Error) { | ||
| throw value; | ||
| } | ||
| return value; | ||
| } | ||
| } | ||
| throw new Error(`Unexpected ${method} ${path}`); | ||
| } | ||
|
|
||
| describe('msp360-backup appAvailabilityCheck', () => { | ||
| it('passes after Provider Login and Administrators ping', async () => { | ||
| const { ctx, passed, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Administrators': [{ Email: 'ops@example.com' }], | ||
| }), | ||
| }); | ||
| await appAvailabilityCheck.run(ctx); | ||
| expect(failed).toHaveLength(0); | ||
| expect(passed.some((r) => r.resourceId === 'msp360-backup')).toBe(true); | ||
| }); | ||
|
|
||
| it('fails when credentials are missing', async () => { | ||
| const { ctx, failed } = makeBackupCtx({ | ||
| credentials: {}, | ||
| fetchImpl: async () => { | ||
| throw new Error('should not call API'); | ||
| }, | ||
| }); | ||
| await appAvailabilityCheck.run(ctx); | ||
| expect(failed.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('fails when the Administrators ping throws after login', async () => { | ||
| const { ctx, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Administrators': new Error('403 forbidden'), | ||
| }), | ||
| }); | ||
| await appAvailabilityCheck.run(ctx); | ||
| expect(failed.some((r) => r.resourceId === 'msp360-backup')).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('msp360-backup employeeAccessCheck', () => { | ||
| it('emits one user row per administrator keyed by lowercased email', async () => { | ||
| const { ctx, passed, failed, calls } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Administrators': [ | ||
| { Email: 'Ops@Example.com', FirstName: 'Ops', LastName: 'Person', Enabled: true }, | ||
| { Email: 'old@example.com', FirstName: 'Old', LastName: 'Admin', Enabled: false }, | ||
| ], | ||
| }), | ||
| }); | ||
| await employeeAccessCheck.run(ctx); | ||
| expect(failed).toHaveLength(0); | ||
| const users = passed.filter((r) => r.resourceType === 'user'); | ||
| expect(users).toHaveLength(2); | ||
| expect(users.map((r) => r.resourceId).sort()).toEqual(['old@example.com', 'ops@example.com']); | ||
| expect(calls.some((c) => c.path.includes('/Users'))).toBe(false); | ||
| }); | ||
|
|
||
| it('fails when the administrator list is empty', async () => { | ||
| const { ctx, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Administrators': [], | ||
| }), | ||
| }); | ||
| await employeeAccessCheck.run(ctx); | ||
| expect(failed.some((r) => r.resourceId === 'msp360-backup-admins')).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('msp360-backup backupLogsCheck', () => { | ||
| it('passes recent successful backups, fails error jobs, and treats stale success as paused', async () => { | ||
| const now = new Date().toISOString(); | ||
| const stale = new Date(Date.now() - 20 * 24 * 60 * 60 * 1000).toISOString(); | ||
| const { ctx, passed, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Monitoring': [ | ||
| { | ||
| PlanName: 'Files', | ||
| ComputerName: 'ok-host', | ||
| PlanType: 3, | ||
| Status: 0, | ||
| LastStart: now, | ||
| PlanId: 'p-ok', | ||
| }, | ||
| { | ||
| PlanName: 'Image', | ||
| ComputerName: 'bad-host', | ||
| PlanType: 1, | ||
| Status: 2, | ||
| LastStart: now, | ||
| PlanId: 'p-fail', | ||
| ErrorMessage: 'disk full', | ||
| }, | ||
| { | ||
| PlanName: 'Old', | ||
| ComputerName: 'stale-host', | ||
| PlanType: 1, | ||
| Status: 0, | ||
| LastStart: stale, | ||
| PlanId: 'p-stale', | ||
| }, | ||
| ], | ||
| }), | ||
| }); | ||
| await backupLogsCheck.run(ctx); | ||
| expect(passed.some((r) => r.resourceId === 'p-ok')).toBe(true); | ||
| expect(failed.some((r) => r.resourceId === 'p-fail')).toBe(true); | ||
| expect(failed.some((r) => r.resourceId === 'p-stale')).toBe(false); | ||
| expect(passed.some((r) => r.resourceId === 'p-stale')).toBe(true); | ||
| }); | ||
|
|
||
| it('fails Running/Unknown instead of treating them as paused', async () => { | ||
| const now = new Date().toISOString(); | ||
| const { ctx, passed, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Monitoring': [ | ||
| { | ||
| PlanName: 'Running job', | ||
| ComputerName: 'host', | ||
| PlanType: 1, | ||
| Status: 3, | ||
| LastStart: now, | ||
| PlanId: 'p-run', | ||
| }, | ||
| { | ||
| PlanName: 'Unknown job', | ||
| ComputerName: 'host', | ||
| PlanType: 1, | ||
| Status: 4, | ||
| LastStart: now, | ||
| PlanId: 'p-unk', | ||
| }, | ||
| ], | ||
| }), | ||
| }); | ||
| await backupLogsCheck.run(ctx); | ||
| expect(failed.some((r) => r.resourceId === 'p-run')).toBe(true); | ||
| expect(failed.some((r) => r.resourceId === 'p-unk')).toBe(true); | ||
| expect(passed.some((r) => r.resourceId === 'p-run' || r.resourceId === 'p-unk')).toBe(false); | ||
| }); | ||
|
|
||
| it('fails when monitoring has no in-scope backup plans', async () => { | ||
| const { ctx, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Monitoring': [{ PlanName: 'Restore files', PlanType: 4, Status: 0, LastStart: new Date().toISOString() }], | ||
| }), | ||
| }); | ||
| await backupLogsCheck.run(ctx); | ||
| expect(failed.some((r) => r.resourceId === 'msp360-backup-plans')).toBe(true); | ||
| }); | ||
|
|
||
| it('fails collection on a malformed monitoring payload', async () => { | ||
| const { ctx, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Monitoring': { unexpected: true }, | ||
| }), | ||
| }); | ||
| await backupLogsCheck.run(ctx); | ||
| expect(failed.some((r) => r.resourceId === 'msp360-monitoring')).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('msp360-backup backupRestorationTestCheck', () => { | ||
| it('passes when a restore-family plan succeeded in the last 90 days', async () => { | ||
| const { ctx, passed, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Monitoring': [ | ||
| { | ||
| PlanName: 'Restore files', | ||
| PlanType: 4, | ||
| Status: 0, | ||
| LastStart: new Date().toISOString(), | ||
| PlanId: 'restore-1', | ||
| }, | ||
| ], | ||
| }), | ||
| }); | ||
| await backupRestorationTestCheck.run(ctx); | ||
| expect(failed).toHaveLength(0); | ||
| expect(passed.some((r) => r.resourceId === 'restore-1')).toBe(true); | ||
| }); | ||
|
|
||
| it('passes as not in scope when no successful restore exists in the window', async () => { | ||
| const { ctx, passed, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Monitoring': [ | ||
| { | ||
| PlanName: 'Files backup', | ||
| PlanType: 3, | ||
| Status: 0, | ||
| LastStart: new Date().toISOString(), | ||
| PlanId: 'backup-only', | ||
| }, | ||
| ], | ||
| }), | ||
| }); | ||
| await backupRestorationTestCheck.run(ctx); | ||
| expect(failed).toHaveLength(0); | ||
| expect(passed.some((r) => r.resourceId === 'msp360-restore-not-in-scope')).toBe(true); | ||
| }); | ||
|
|
||
| it('fails a restore-family job that ran in the window with an error status', async () => { | ||
| const { ctx, passed, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Monitoring': [ | ||
| { | ||
| PlanName: 'SQLResore', | ||
| PlanType: 'SQLResore', | ||
| Status: 2, | ||
| LastStart: new Date().toISOString(), | ||
| PlanId: 'restore-fail', | ||
| ErrorMessage: 'disk missing', | ||
| }, | ||
| ], | ||
| }), | ||
| }); | ||
| await backupRestorationTestCheck.run(ctx); | ||
| expect(failed.some((r) => r.resourceId === 'restore-fail')).toBe(true); | ||
| expect(passed.some((r) => r.resourceId === 'msp360-restore-not-in-scope')).toBe(false); | ||
| }); | ||
|
|
||
| it('fails an in-window restore with a missing or unrecognized status instead of N/A', async () => { | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| const { ctx, passed, failed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Monitoring': [ | ||
| { | ||
| PlanName: 'Restore files', | ||
| PlanType: 4, | ||
| LastStart: new Date().toISOString(), | ||
| PlanId: 'restore-missing-status', | ||
| }, | ||
| { | ||
| PlanName: 'Restore verify', | ||
| PlanType: 4, | ||
| Status: 'bogus', | ||
| LastStart: new Date().toISOString(), | ||
| PlanId: 'restore-unrecognized-status', | ||
| }, | ||
| ], | ||
| }), | ||
| }); | ||
| await backupRestorationTestCheck.run(ctx); | ||
| expect(failed.some((r) => r.resourceId === 'restore-missing-status')).toBe(true); | ||
| expect(failed.some((r) => r.resourceId === 'restore-unrecognized-status')).toBe(true); | ||
| expect(passed.some((r) => r.resourceId === 'msp360-restore-not-in-scope')).toBe(false); | ||
| }); | ||
|
|
||
| it('fails collection on a malformed monitoring payload instead of N/A', async () => { | ||
| const { ctx, failed, passed } = makeBackupCtx({ | ||
| fetchImpl: async (path, init) => | ||
| router(path, init?.method, { | ||
| '/Monitoring': { foo: 1 }, | ||
| }), | ||
| }); | ||
| await backupRestorationTestCheck.run(ctx); | ||
| expect(failed.some((r) => r.resourceId === 'msp360-restore-monitoring')).toBe(true); | ||
| expect(passed.some((r) => r.resourceId === 'msp360-restore-not-in-scope')).toBe(false); | ||
| }); | ||
| }); | ||
41 changes: 41 additions & 0 deletions
41
packages/integration-platform/src/manifests/msp360-backup/__tests__/monitoring.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { describe, expect, it } from 'bun:test'; | ||
| import { | ||
| isBackupPlan, | ||
| isIncompleteStatus, | ||
| isRestorePlan, | ||
| parseMonitoringPayload, | ||
| rowId, | ||
| } from '../monitoring'; | ||
|
|
||
| describe('msp360-backup monitoring helpers', () => { | ||
| it('treats a known list envelope as ok and other objects as malformed', () => { | ||
| expect(parseMonitoringPayload([]).ok).toBe(true); | ||
| expect(parseMonitoringPayload({ data: [] }).ok).toBe(true); | ||
| expect(parseMonitoringPayload({ items: [{ PlanName: 'x' }] }).ok).toBe(true); | ||
| expect(parseMonitoringPayload({ unexpected: true }).ok).toBe(false); | ||
| expect(parseMonitoringPayload(null).ok).toBe(false); | ||
| expect(parseMonitoringPayload('nope').ok).toBe(false); | ||
| }); | ||
|
|
||
| it('recognizes SQLResore spelling and restore numeric types before name fallback', () => { | ||
| expect(isRestorePlan({ PlanType: 8, PlanName: 'SQL' })).toBe(true); | ||
| expect(isRestorePlan({ PlanType: 'SQLResore' })).toBe(true); | ||
| expect(isRestorePlan({ PlanType: 4, PlanName: 'Files' })).toBe(true); | ||
| expect(isRestorePlan({ PlanType: 3, PlanName: 'Restore-looking backup' })).toBe(false); | ||
| expect(isBackupPlan({ PlanType: 3, PlanName: 'Restore-looking backup' })).toBe(true); | ||
| }); | ||
|
|
||
| it('treats Running and Unknown as incomplete, not failed', () => { | ||
| expect(isIncompleteStatus(3)).toBe(true); | ||
| expect(isIncompleteStatus(4)).toBe(true); | ||
| expect(isIncompleteStatus('running')).toBe(true); | ||
| expect(isIncompleteStatus(0)).toBe(false); | ||
| expect(isIncompleteStatus(2)).toBe(false); | ||
| }); | ||
|
|
||
| it('includes the loop index when PlanId is missing so rows do not collide', () => { | ||
| expect(rowId({ ComputerName: 'a', PlanName: 'Files' }, 0)).toBe('a:Files:0'); | ||
| expect(rowId({ ComputerName: 'a', PlanName: 'Files' }, 1)).toBe('a:Files:1'); | ||
| expect(rowId({ PlanId: 'p1', ComputerName: 'a' }, 9)).toBe('p1'); | ||
| }); | ||
| }); |
54 changes: 54 additions & 0 deletions
54
packages/integration-platform/src/manifests/msp360-backup/__tests__/test-utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import type { CheckContext, CheckFindingResult, CheckPassingResult } from '../../../types'; | ||
|
|
||
| export interface MockFetchCall { | ||
| method: 'GET' | 'POST'; | ||
| path: string; | ||
| } | ||
|
|
||
| export function makeBackupCtx(options: { | ||
| credentials?: Record<string, string | string[]>; | ||
| fetchImpl: (path: string, init?: { method?: string }) => Promise<unknown>; | ||
| }): { | ||
| ctx: CheckContext; | ||
| passed: CheckPassingResult[]; | ||
| failed: CheckFindingResult[]; | ||
| calls: MockFetchCall[]; | ||
| } { | ||
| const passed: CheckPassingResult[] = []; | ||
| const failed: CheckFindingResult[] = []; | ||
| const calls: MockFetchCall[] = []; | ||
|
|
||
| const ctx: CheckContext = { | ||
| accessToken: '', | ||
| credentials: options.credentials ?? { | ||
| username: 'api-user', | ||
| password: 'secret', | ||
| baseUrl: 'https://api.mspbackups.com', | ||
| }, | ||
| variables: {}, | ||
| connectionId: 'conn_1', | ||
| organizationId: 'org_1', | ||
| metadata: {}, | ||
| log: () => {}, | ||
| warn: () => {}, | ||
| error: () => {}, | ||
| pass: (result) => { | ||
| passed.push(result); | ||
| }, | ||
| fail: (result) => { | ||
| failed.push(result); | ||
| }, | ||
| fetch: (async (path: string) => { | ||
| calls.push({ method: 'GET', path }); | ||
| return options.fetchImpl(path, { method: 'GET' }); | ||
| }) as CheckContext['fetch'], | ||
| post: (async (path: string) => { | ||
| calls.push({ method: 'POST', path }); | ||
| return options.fetchImpl(path, { method: 'POST' }); | ||
| }) as CheckContext['post'], | ||
| fetchAllPages: (async () => []) as CheckContext['fetchAllPages'], | ||
| graphql: (async () => ({})) as CheckContext['graphql'], | ||
| } as CheckContext; | ||
|
|
||
| return { ctx, passed, failed, calls }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.