forked from mattermost/mattermost-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix upload permissions and centralize download permissions (mattermos…
- Loading branch information
Showing
7 changed files
with
284 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import {SYSTEM_IDENTIFIERS} from '@constants/database'; | ||
import DatabaseManager from '@database/manager'; | ||
|
||
import {observeCanDownloadFiles, observeCanUploadFiles} from './system'; | ||
|
||
import type ServerDataOperator from '@database/operator/server_data_operator'; | ||
import type {Database} from '@nozbe/watermelondb'; | ||
|
||
describe('observeCanUploadFiles', () => { | ||
const serverUrl = 'baseHandler.test.com'; | ||
let database: Database; | ||
let operator: ServerDataOperator; | ||
beforeEach(async () => { | ||
await DatabaseManager.init([serverUrl]); | ||
const serverDatabaseAndOperator = DatabaseManager.getServerDatabaseAndOperator(serverUrl); | ||
database = serverDatabaseAndOperator.database; | ||
operator = serverDatabaseAndOperator.operator; | ||
}); | ||
afterEach(async () => { | ||
await DatabaseManager.destroyServerDatabase(serverUrl); | ||
}); | ||
|
||
it('should return true if no file attachment config value', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableMobileFileUpload', value: 'true'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
observeCanUploadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return false if file attachment config value is false', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableFileAttachments', value: 'false'}, {id: 'EnableMobileFileUpload', value: 'true'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
observeCanUploadFiles(database).subscribe((data) => { | ||
if (data === false) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if file attachment config value is true and there is no license', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableFileAttachments', value: 'true'}, {id: 'EnableMobileFileUpload', value: 'false'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
observeCanUploadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if file attachment config value is true and server is not licensed', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableFileAttachments', value: 'true'}, {id: 'EnableMobileFileUpload', value: 'false'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {isLicensed: false}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanUploadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if file attachment config value is true and server is licensed, but no compliance is set', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableFileAttachments', value: 'true'}, {id: 'EnableMobileFileUpload', value: 'false'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true'}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanUploadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if file attachment config value is true and server is licensed, but compliance is set to false', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableFileAttachments', value: 'true'}, {id: 'EnableMobileFileUpload', value: 'false'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true', Compliance: 'false'}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanUploadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if file attachment config value is true and server is licensed and compliance is set to true, but EnableMobileFileUpload is not set', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableFileAttachments', value: 'true'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true', Compliance: 'true'}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanUploadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return false if file attachment config value is true and server is licensed and compliance is set to true, but EnableMobileFileUpload is set to false', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableFileAttachments', value: 'true'}, {id: 'EnableMobileFileUpload', value: 'false'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true', Compliance: 'true'}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanUploadFiles(database).subscribe((data) => { | ||
if (data === false) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if file attachment config value is true and server is licensed and compliance is set to true, but EnableMobileFileUpload is set to true', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableFileAttachments', value: 'true'}, {id: 'EnableMobileFileUpload', value: 'true'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true', Compliance: 'true'}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanUploadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
}); | ||
|
||
describe('observeCanDownloadFiles', () => { | ||
const serverUrl = 'baseHandler.test.com'; | ||
let database: Database; | ||
let operator: ServerDataOperator; | ||
beforeEach(async () => { | ||
await DatabaseManager.init([serverUrl]); | ||
const serverDatabaseAndOperator = DatabaseManager.getServerDatabaseAndOperator(serverUrl); | ||
database = serverDatabaseAndOperator.database; | ||
operator = serverDatabaseAndOperator.operator; | ||
}); | ||
afterEach(async () => { | ||
await DatabaseManager.destroyServerDatabase(serverUrl); | ||
}); | ||
|
||
it('should return true if there is no license', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableMobileFileDownload', value: 'false'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
observeCanDownloadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if server is not licensed', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableMobileFileDownload', value: 'false'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {isLicensed: false}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanDownloadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if server is licensed, but no compliance is set', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableMobileFileDownload', value: 'false'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true'}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanDownloadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if server is licensed, but compliance is set to false', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableMobileFileDownload', value: 'false'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true', Compliance: 'false'}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanDownloadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if is licensed and compliance is set to true, but EnableMobileFileDownload is not set', (done) => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true', Compliance: 'true'}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanDownloadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return false if server is licensed and compliance is set to true, but EnableMobileFileDownload is set to false', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableMobileFileDownload', value: 'false'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true', Compliance: 'true'}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanDownloadFiles(database).subscribe((data) => { | ||
if (data === false) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
|
||
it('should return true if server is licensed and compliance is set to true, but EnableMobileFileDownload is set to true', (done) => { | ||
operator.handleConfigs({configs: [{id: 'EnableMobileFileDownload', value: 'true'}], prepareRecordsOnly: false, configsToDelete: []}).then(() => { | ||
operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true', Compliance: 'true'}}], prepareRecordsOnly: false}).then(() => { | ||
observeCanDownloadFiles(database).subscribe((data) => { | ||
if (data === true) { | ||
done(); | ||
} else { | ||
done.fail(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, 1500); | ||
}); |
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
Oops, something went wrong.