-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/reject-invalid-paths2'
- Loading branch information
Showing
27 changed files
with
565 additions
and
173 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
82 changes: 82 additions & 0 deletions
82
shared/packages/worker/src/worker/accessorHandlers/__tests__/fileShare.spec.ts
This file contains 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,82 @@ | ||
import { | ||
AccessorOnPackage, | ||
protectString, | ||
setupLogger, | ||
initializeLogger, | ||
ProcessConfig, | ||
Expectation, | ||
Accessor, | ||
} from '@sofie-package-manager/api' | ||
import { Content, FileShareAccessorHandle } from '../fileShare' | ||
import { PassiveTestWorker } from './lib' | ||
|
||
const processConfig: ProcessConfig = { | ||
logPath: undefined, | ||
logLevel: undefined, | ||
unsafeSSL: false, | ||
certificates: [], | ||
} | ||
initializeLogger({ process: processConfig }) | ||
test('checkHandleBasic', () => { | ||
const logger = setupLogger( | ||
{ | ||
process: processConfig, | ||
}, | ||
'' | ||
) | ||
const worker = new PassiveTestWorker(logger) | ||
|
||
function getFileShareAccessor( | ||
accessor: AccessorOnPackage.FileShare, | ||
content: Content, | ||
workOptions: Expectation.WorkOptions.Base & | ||
Expectation.WorkOptions.RemoveDelay & | ||
Expectation.WorkOptions.UseTemporaryFilePath = {} | ||
) { | ||
accessor.type = Accessor.AccessType.FILE_SHARE | ||
return new FileShareAccessorHandle(worker, protectString('share0'), accessor, content, workOptions) | ||
} | ||
|
||
expect(() => getFileShareAccessor({}, {}).checkHandleBasic()).toThrowError('Bad input data') | ||
|
||
// missing accessor.folderPath: | ||
expect(getFileShareAccessor({}, { filePath: 'amb.amp4' }).checkHandleBasic()).toMatchObject({ | ||
success: false, | ||
reason: { tech: 'Folder path not set' }, | ||
}) | ||
|
||
// All OK: | ||
expect( | ||
getFileShareAccessor({ folderPath: '\\\\nas01\\media' }, { filePath: 'amb.amp4' }).checkHandleBasic() | ||
).toMatchObject({ | ||
success: true, | ||
}) | ||
|
||
// Absolute file path: | ||
expect( | ||
getFileShareAccessor({ folderPath: '\\\\nas01\\media' }, { filePath: '//secret/amb.amp4' }).checkHandleBasic() | ||
).toMatchObject({ | ||
success: false, | ||
reason: { tech: expect.stringMatching(/File path.*absolute path/) }, | ||
}) | ||
expect( | ||
getFileShareAccessor( | ||
{ folderPath: '\\\\nas01\\media' }, | ||
{ filePath: 'C:\\secret\\amb.amp4' } | ||
).checkHandleBasic() | ||
).toMatchObject({ | ||
success: false, | ||
reason: { tech: expect.stringMatching(/File path.*absolute path/) }, | ||
}) | ||
|
||
// File path outside of folder path: | ||
expect( | ||
getFileShareAccessor({ folderPath: '//nas01/media' }, { filePath: '../secret/amb.amp4' }).checkHandleBasic() | ||
).toMatchObject({ | ||
success: false, | ||
reason: { | ||
user: `File path is outside of folder path`, | ||
tech: expect.stringMatching(/Full path.*does not start with/), | ||
}, | ||
}) | ||
}) |
65 changes: 65 additions & 0 deletions
65
shared/packages/worker/src/worker/accessorHandlers/__tests__/lib.ts
This file contains 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,65 @@ | ||
import { protectString, LoggerInstance } from '@sofie-package-manager/api' | ||
import { BaseWorker } from '../../worker' | ||
|
||
export class PassiveTestWorker extends BaseWorker { | ||
constructor(logger: LoggerInstance) { | ||
super( | ||
logger, | ||
{ | ||
config: { | ||
workerId: protectString('test'), | ||
sourcePackageStabilityThreshold: 0, | ||
windowsDriveLetters: ['X', 'Y', 'Z'], | ||
}, | ||
location: { | ||
// localComputerId?: string | ||
localNetworkIds: [], | ||
}, | ||
workerStorageWrite: () => { | ||
throw new Error('Method not implemented.') | ||
}, | ||
workerStorageRead: () => { | ||
throw new Error('Method not implemented.') | ||
}, | ||
}, | ||
async () => { | ||
throw new Error('Method not implemented.') | ||
}, | ||
'passive-test-worker' | ||
) | ||
} | ||
|
||
async init() { | ||
throw new Error('Method not implemented.') | ||
} | ||
terminate() { | ||
throw new Error('Method not implemented.') | ||
} | ||
async doYouSupportExpectation(): Promise<any> { | ||
throw new Error('Method not implemented.') | ||
} | ||
async getCostFortExpectation(): Promise<any> { | ||
throw new Error('Method not implemented.') | ||
} | ||
async isExpectationReadyToStartWorkingOn(): Promise<any> { | ||
throw new Error('Method not implemented.') | ||
} | ||
async isExpectationFulfilled(): Promise<any> { | ||
throw new Error('Method not implemented.') | ||
} | ||
async workOnExpectation(): Promise<any> { | ||
throw new Error('Method not implemented.') | ||
} | ||
async removeExpectation(): Promise<any> { | ||
throw new Error('Method not implemented.') | ||
} | ||
async doYouSupportPackageContainer(): Promise<any> { | ||
throw new Error('Method not implemented.') | ||
} | ||
async runPackageContainerCronJob(): Promise<any> { | ||
throw new Error('Method not implemented.') | ||
} | ||
async setupPackageContainerMonitors(): Promise<any> { | ||
throw new Error('Method not implemented.') | ||
} | ||
} |
Oops, something went wrong.