2019-11-29 12:59:40 +01:00
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
package app
import (
"fmt"
2019-07-11 12:00:12 -04:00
"io/ioutil"
"os"
"path/filepath"
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2019-11-28 14:39:38 +01:00
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
)
func TestCreateBot ( t * testing . T ) {
t . Run ( "invalid bot" , func ( t * testing . T ) {
t . Run ( "relative to user" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
_ , err := th . App . CreateBot ( & model . Bot {
Username : "invalid username" ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . NotNil ( t , err )
require . Equal ( t , "model.user.is_valid.username.app_error" , err . Id )
} )
t . Run ( "relative to bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
_ , err := th . App . CreateBot ( & model . Bot {
Username : "username" ,
Description : strings . Repeat ( "x" , 1025 ) ,
OwnerId : th . BasicUser . Id ,
} )
require . NotNil ( t , err )
require . Equal ( t , "model.bot.is_valid.description.app_error" , err . Id )
} )
2019-10-30 17:00:43 -04:00
t . Run ( "username contains . character" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
bot , err := th . App . CreateBot ( & model . Bot {
Username : "username." ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . NotNil ( t , err )
require . Nil ( t , bot )
require . Equal ( t , "model.user.is_valid.email.app_error" , err . Id )
} )
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
} )
t . Run ( "create bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
bot , err := th . App . CreateBot ( & model . Bot {
Username : "username" ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot . UserId )
assert . Equal ( t , "username" , bot . Username )
assert . Equal ( t , "a bot" , bot . Description )
assert . Equal ( t , th . BasicUser . Id , bot . OwnerId )
2019-06-13 07:36:13 -04:00
// Check that a post was created to add bot to team and channels
channel , err := th . App . GetOrCreateDirectChannel ( bot . UserId , th . BasicUser . Id )
require . Nil ( t , err )
posts , err := th . App . GetPosts ( channel . Id , 0 , 1 )
require . Nil ( t , err )
postArray := posts . ToSlice ( )
assert . Len ( t , postArray , 1 )
assert . Equal ( t , postArray [ 0 ] . Type , model . POST_ADD_BOT_TEAMS_CHANNELS )
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
} )
t . Run ( "create bot, username already used by a non-bot user" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
_ , err := th . App . CreateBot ( & model . Bot {
Username : th . BasicUser . Username ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . NotNil ( t , err )
2020-10-30 11:14:06 +05:30
require . Equal ( t , "app.user.save.username_exists.app_error" , err . Id )
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
} )
}
func TestPatchBot ( t * testing . T ) {
t . Run ( "invalid patch for user" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
bot , err := th . App . CreateBot ( & model . Bot {
Username : "username" ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot . UserId )
botPatch := & model . BotPatch {
Username : sToP ( "invalid username" ) ,
DisplayName : sToP ( "an updated bot" ) ,
Description : sToP ( "updated bot" ) ,
}
_ , err = th . App . PatchBot ( bot . UserId , botPatch )
require . NotNil ( t , err )
require . Equal ( t , "model.user.is_valid.username.app_error" , err . Id )
} )
t . Run ( "invalid patch for bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
bot , err := th . App . CreateBot ( & model . Bot {
Username : "username" ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot . UserId )
botPatch := & model . BotPatch {
Username : sToP ( "username" ) ,
DisplayName : sToP ( "display name" ) ,
Description : sToP ( strings . Repeat ( "x" , 1025 ) ) ,
}
_ , err = th . App . PatchBot ( bot . UserId , botPatch )
require . NotNil ( t , err )
require . Equal ( t , "model.bot.is_valid.description.app_error" , err . Id )
} )
t . Run ( "patch bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
bot := & model . Bot {
Username : "username" ,
DisplayName : "bot" ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
}
createdBot , err := th . App . CreateBot ( bot )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( createdBot . UserId )
botPatch := & model . BotPatch {
Username : sToP ( "username2" ) ,
DisplayName : sToP ( "updated bot" ) ,
Description : sToP ( "an updated bot" ) ,
}
patchedBot , err := th . App . PatchBot ( createdBot . UserId , botPatch )
require . Nil ( t , err )
2019-10-31 11:25:19 -05:00
// patchedBot should create a new .UpdateAt time
require . NotEqual ( t , createdBot . UpdateAt , patchedBot . UpdateAt )
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
createdBot . Username = "username2"
createdBot . DisplayName = "updated bot"
createdBot . Description = "an updated bot"
createdBot . UpdateAt = patchedBot . UpdateAt
require . Equal ( t , createdBot , patchedBot )
} )
t . Run ( "patch bot, username already used by a non-bot user" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
bot , err := th . App . CreateBot ( & model . Bot {
Username : "username" ,
DisplayName : "bot" ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot . UserId )
botPatch := & model . BotPatch {
Username : sToP ( th . BasicUser2 . Username ) ,
}
_ , err = th . App . PatchBot ( bot . UserId , botPatch )
require . NotNil ( t , err )
2020-10-26 06:41:27 -03:00
require . Equal ( t , "app.user.update.find.app_error" , err . Id )
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
} )
}
func TestGetBot ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
bot1 , err := th . App . CreateBot ( & model . Bot {
Username : "username" ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot1 . UserId )
bot2 , err := th . App . CreateBot ( & model . Bot {
Username : "username2" ,
Description : "a second bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot2 . UserId )
deletedBot , err := th . App . CreateBot ( & model . Bot {
Username : "username3" ,
Description : "a deleted bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . Nil ( t , err )
deletedBot , err = th . App . UpdateBotActive ( deletedBot . UserId , false )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( deletedBot . UserId )
t . Run ( "get unknown bot" , func ( t * testing . T ) {
_ , err := th . App . GetBot ( model . NewId ( ) , false )
require . NotNil ( t , err )
require . Equal ( t , "store.sql_bot.get.missing.app_error" , err . Id )
} )
t . Run ( "get bot1" , func ( t * testing . T ) {
bot , err := th . App . GetBot ( bot1 . UserId , false )
require . Nil ( t , err )
assert . Equal ( t , bot1 , bot )
} )
t . Run ( "get bot2" , func ( t * testing . T ) {
bot , err := th . App . GetBot ( bot2 . UserId , false )
require . Nil ( t , err )
assert . Equal ( t , bot2 , bot )
} )
t . Run ( "get deleted bot" , func ( t * testing . T ) {
_ , err := th . App . GetBot ( deletedBot . UserId , false )
require . NotNil ( t , err )
require . Equal ( t , "store.sql_bot.get.missing.app_error" , err . Id )
} )
t . Run ( "get deleted bot, include deleted" , func ( t * testing . T ) {
bot , err := th . App . GetBot ( deletedBot . UserId , true )
require . Nil ( t , err )
assert . Equal ( t , deletedBot , bot )
} )
}
func TestGetBots ( t * testing . T ) {
2020-07-13 23:04:05 +05:30
th := Setup ( t )
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
defer th . TearDown ( )
OwnerId1 := model . NewId ( )
OwnerId2 := model . NewId ( )
bot1 , err := th . App . CreateBot ( & model . Bot {
Username : "username" ,
Description : "a bot" ,
OwnerId : OwnerId1 ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot1 . UserId )
deletedBot1 , err := th . App . CreateBot ( & model . Bot {
Username : "username4" ,
Description : "a deleted bot" ,
OwnerId : OwnerId1 ,
} )
require . Nil ( t , err )
deletedBot1 , err = th . App . UpdateBotActive ( deletedBot1 . UserId , false )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( deletedBot1 . UserId )
bot2 , err := th . App . CreateBot ( & model . Bot {
Username : "username2" ,
Description : "a second bot" ,
OwnerId : OwnerId1 ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot2 . UserId )
bot3 , err := th . App . CreateBot ( & model . Bot {
Username : "username3" ,
Description : "a third bot" ,
OwnerId : OwnerId1 ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot3 . UserId )
bot4 , err := th . App . CreateBot ( & model . Bot {
Username : "username5" ,
Description : "a fourth bot" ,
OwnerId : OwnerId2 ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot4 . UserId )
deletedBot2 , err := th . App . CreateBot ( & model . Bot {
Username : "username6" ,
Description : "a deleted bot" ,
OwnerId : OwnerId2 ,
} )
require . Nil ( t , err )
deletedBot2 , err = th . App . UpdateBotActive ( deletedBot2 . UserId , false )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( deletedBot2 . UserId )
t . Run ( "get bots, page=0, perPage=10" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 0 ,
PerPage : 10 ,
OwnerId : "" ,
IncludeDeleted : false ,
} )
require . Nil ( t , err )
assert . Equal ( t , model . BotList { bot1 , bot2 , bot3 , bot4 } , bots )
} )
t . Run ( "get bots, page=0, perPage=1" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 0 ,
PerPage : 1 ,
OwnerId : "" ,
IncludeDeleted : false ,
} )
require . Nil ( t , err )
assert . Equal ( t , model . BotList { bot1 } , bots )
} )
t . Run ( "get bots, page=1, perPage=2" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 1 ,
PerPage : 2 ,
OwnerId : "" ,
IncludeDeleted : false ,
} )
require . Nil ( t , err )
assert . Equal ( t , model . BotList { bot3 , bot4 } , bots )
} )
t . Run ( "get bots, page=2, perPage=2" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 2 ,
PerPage : 2 ,
OwnerId : "" ,
IncludeDeleted : false ,
} )
require . Nil ( t , err )
assert . Equal ( t , model . BotList { } , bots )
} )
t . Run ( "get bots, page=0, perPage=10, include deleted" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 0 ,
PerPage : 10 ,
OwnerId : "" ,
IncludeDeleted : true ,
} )
require . Nil ( t , err )
assert . Equal ( t , model . BotList { bot1 , deletedBot1 , bot2 , bot3 , bot4 , deletedBot2 } , bots )
} )
t . Run ( "get bots, page=0, perPage=1, include deleted" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 0 ,
PerPage : 1 ,
OwnerId : "" ,
IncludeDeleted : true ,
} )
require . Nil ( t , err )
assert . Equal ( t , model . BotList { bot1 } , bots )
} )
t . Run ( "get bots, page=1, perPage=2, include deleted" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 1 ,
PerPage : 2 ,
OwnerId : "" ,
IncludeDeleted : true ,
} )
require . Nil ( t , err )
assert . Equal ( t , model . BotList { bot2 , bot3 } , bots )
} )
t . Run ( "get bots, page=2, perPage=2, include deleted" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 2 ,
PerPage : 2 ,
OwnerId : "" ,
IncludeDeleted : true ,
} )
require . Nil ( t , err )
assert . Equal ( t , model . BotList { bot4 , deletedBot2 } , bots )
} )
t . Run ( "get offset=0, limit=10, creator id 1" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 0 ,
PerPage : 10 ,
OwnerId : OwnerId1 ,
IncludeDeleted : false ,
} )
require . Nil ( t , err )
require . Equal ( t , model . BotList { bot1 , bot2 , bot3 } , bots )
} )
t . Run ( "get offset=0, limit=10, creator id 2" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 0 ,
PerPage : 10 ,
OwnerId : OwnerId2 ,
IncludeDeleted : false ,
} )
require . Nil ( t , err )
require . Equal ( t , model . BotList { bot4 } , bots )
} )
t . Run ( "get offset=0, limit=10, include deleted, creator id 1" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 0 ,
PerPage : 10 ,
OwnerId : OwnerId1 ,
IncludeDeleted : true ,
} )
require . Nil ( t , err )
require . Equal ( t , model . BotList { bot1 , deletedBot1 , bot2 , bot3 } , bots )
} )
t . Run ( "get offset=0, limit=10, include deleted, creator id 2" , func ( t * testing . T ) {
bots , err := th . App . GetBots ( & model . BotGetOptions {
Page : 0 ,
PerPage : 10 ,
OwnerId : OwnerId2 ,
IncludeDeleted : true ,
} )
require . Nil ( t , err )
require . Equal ( t , model . BotList { bot4 , deletedBot2 } , bots )
} )
}
func TestUpdateBotActive ( t * testing . T ) {
t . Run ( "unknown bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
_ , err := th . App . UpdateBotActive ( model . NewId ( ) , false )
require . NotNil ( t , err )
2020-10-26 06:41:27 -03:00
require . Equal ( t , "app.user.missing_account.const" , err . Id )
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
} )
t . Run ( "disable/enable bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
bot , err := th . App . CreateBot ( & model . Bot {
Username : "username" ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot . UserId )
disabledBot , err := th . App . UpdateBotActive ( bot . UserId , false )
require . Nil ( t , err )
require . NotEqual ( t , 0 , disabledBot . DeleteAt )
// Disabling should be idempotent
disabledBotAgain , err := th . App . UpdateBotActive ( bot . UserId , false )
require . Nil ( t , err )
require . Equal ( t , disabledBot . DeleteAt , disabledBotAgain . DeleteAt )
reenabledBot , err := th . App . UpdateBotActive ( bot . UserId , true )
require . Nil ( t , err )
require . EqualValues ( t , 0 , reenabledBot . DeleteAt )
// Re-enabling should be idempotent
reenabledBotAgain , err := th . App . UpdateBotActive ( bot . UserId , true )
require . Nil ( t , err )
require . Equal ( t , reenabledBot . DeleteAt , reenabledBotAgain . DeleteAt )
} )
}
func TestPermanentDeleteBot ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
bot , err := th . App . CreateBot ( & model . Bot {
Username : "username" ,
Description : "a bot" ,
OwnerId : th . BasicUser . Id ,
} )
require . Nil ( t , err )
require . Nil ( t , th . App . PermanentDeleteBot ( bot . UserId ) )
_ , err = th . App . GetBot ( bot . UserId , false )
require . NotNil ( t , err )
require . Equal ( t , "store.sql_bot.get.missing.app_error" , err . Id )
}
func TestDisableUserBots ( t * testing . T ) {
2020-07-13 23:04:05 +05:30
th := Setup ( t )
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
defer th . TearDown ( )
ownerId1 := model . NewId ( )
ownerId2 := model . NewId ( )
bots := [ ] * model . Bot { }
defer func ( ) {
for _ , bot := range bots {
th . App . PermanentDeleteBot ( bot . UserId )
}
} ( )
for i := 0 ; i < 46 ; i ++ {
bot , err := th . App . CreateBot ( & model . Bot {
Username : fmt . Sprintf ( "username%v" , i ) ,
Description : "a bot" ,
OwnerId : ownerId1 ,
} )
require . Nil ( t , err )
bots = append ( bots , bot )
}
require . Len ( t , bots , 46 )
u2bot1 , err := th . App . CreateBot ( & model . Bot {
Username : "username_nodisable" ,
Description : "a bot" ,
OwnerId : ownerId2 ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( u2bot1 . UserId )
err = th . App . disableUserBots ( ownerId1 )
require . Nil ( t , err )
// Check all bots and corrensponding users are disabled for creator 1
for _ , bot := range bots {
retbot , err2 := th . App . GetBot ( bot . UserId , true )
require . Nil ( t , err2 )
require . NotZero ( t , retbot . DeleteAt , bot . Username )
}
// Check bots and corresponding user not disabled for creator 2
bot , err := th . App . GetBot ( u2bot1 . UserId , true )
require . Nil ( t , err )
require . Zero ( t , bot . DeleteAt )
user , err := th . App . GetUser ( u2bot1 . UserId )
require . Nil ( t , err )
require . Zero ( t , user . DeleteAt )
// Bad id doesn't do anything or break horribly
err = th . App . disableUserBots ( model . NewId ( ) )
require . Nil ( t , err )
}
2019-12-06 20:00:47 -06:00
func TestNotifySysadminsBotOwnerDisabled ( t * testing . T ) {
2020-07-13 23:04:05 +05:30
th := Setup ( t )
2019-12-06 20:00:47 -06:00
defer th . TearDown ( )
userBots := [ ] * model . Bot { }
defer func ( ) {
for _ , bot := range userBots {
th . App . PermanentDeleteBot ( bot . UserId )
}
} ( )
// // Create two sysadmins
sysadmin1 := model . User {
Email : "sys1@example.com" ,
Nickname : "nn_sysadmin1" ,
Password : "hello1" ,
Username : "un_sysadmin1" ,
Roles : model . SYSTEM_ADMIN_ROLE_ID + " " + model . SYSTEM_USER_ROLE_ID }
_ , err := th . App . CreateUser ( & sysadmin1 )
require . Nil ( t , err , "failed to create user" )
th . App . UpdateUserRoles ( sysadmin1 . Id , model . SYSTEM_USER_ROLE_ID + " " + model . SYSTEM_ADMIN_ROLE_ID , false )
sysadmin2 := model . User {
Email : "sys2@example.com" ,
Nickname : "nn_sysadmin2" ,
Password : "hello1" ,
Username : "un_sysadmin2" ,
Roles : model . SYSTEM_ADMIN_ROLE_ID + " " + model . SYSTEM_USER_ROLE_ID }
_ , err = th . App . CreateUser ( & sysadmin2 )
require . Nil ( t , err , "failed to create user" )
th . App . UpdateUserRoles ( sysadmin2 . Id , model . SYSTEM_USER_ROLE_ID + " " + model . SYSTEM_ADMIN_ROLE_ID , false )
// create user to be disabled
user1 , err := th . App . CreateUser ( & model . User {
Email : "user1@example.com" ,
Username : "user1_disabled" ,
Nickname : "user1" ,
Password : "Password1" ,
} )
require . Nil ( t , err , "failed to create user" )
// create user that doesn't own any bots
user2 , err := th . App . CreateUser ( & model . User {
Email : "user2@example.com" ,
Username : "user2_disabled" ,
Nickname : "user2" ,
Password : "Password1" ,
} )
require . Nil ( t , err , "failed to create user" )
const numBotsToPrint = 10
// create bots owned by user (equal to numBotsToPrint)
var bot * model . Bot
for i := 0 ; i < numBotsToPrint ; i ++ {
bot , err = th . App . CreateBot ( & model . Bot {
Username : fmt . Sprintf ( "bot%v" , i ) ,
Description : "a bot" ,
OwnerId : user1 . Id ,
} )
require . Nil ( t , err )
userBots = append ( userBots , bot )
}
assert . Len ( t , userBots , 10 )
// get DM channels for sysadmin1 and sysadmin2
channelSys1 , appErr := th . App . GetOrCreateDirectChannel ( sysadmin1 . Id , sysadmin1 . Id )
require . Nil ( t , appErr )
channelSys2 , appErr := th . App . GetOrCreateDirectChannel ( sysadmin2 . Id , sysadmin2 . Id )
require . Nil ( t , appErr )
// send notification for user without bots
err = th . App . notifySysadminsBotOwnerDeactivated ( user2 . Id )
require . Nil ( t , err )
// get posts from sysadmin1 and sysadmin2 DM channels
posts1 , err := th . App . GetPosts ( channelSys1 . Id , 0 , 5 )
require . Nil ( t , err )
2019-12-22 12:35:31 +01:00
assert . Empty ( t , posts1 . Order )
2019-12-06 20:00:47 -06:00
posts2 , err := th . App . GetPosts ( channelSys2 . Id , 0 , 5 )
require . Nil ( t , err )
2019-12-22 12:35:31 +01:00
assert . Empty ( t , posts2 . Order )
2019-12-06 20:00:47 -06:00
// send notification for user with bots
err = th . App . notifySysadminsBotOwnerDeactivated ( user1 . Id )
require . Nil ( t , err )
// get posts from sysadmin1 and sysadmin2 DM channels
posts1 , err = th . App . GetPosts ( channelSys1 . Id , 0 , 5 )
require . Nil ( t , err )
assert . Len ( t , posts1 . Order , 1 )
posts2 , err = th . App . GetPosts ( channelSys2 . Id , 0 , 5 )
require . Nil ( t , err )
assert . Len ( t , posts2 . Order , 1 )
post := posts1 . Posts [ posts1 . Order [ 0 ] ] . Message
assert . Equal ( t , "user1_disabled was deactivated. They managed the following bot accounts which have now been disabled.\n\n* bot0\n* bot1\n* bot2\n* bot3\n* bot4\n* bot5\n* bot6\n* bot7\n* bot8\n* bot9\nYou can take ownership of each bot by enabling it at **Integrations > Bot Accounts** and creating new tokens for the bot.\n\nFor more information, see our [documentation](https://docs.mattermost.com/developer/bot-accounts.html#what-happens-when-a-user-who-owns-bot-accounts-is-disabled)." , post )
// print all bots
th . App . UpdateConfig ( func ( cfg * model . Config ) { * cfg . ServiceSettings . DisableBotsWhenOwnerIsDeactivated = true } )
message := th . App . getDisableBotSysadminMessage ( user1 , userBots )
assert . Equal ( t , "user1_disabled was deactivated. They managed the following bot accounts which have now been disabled.\n\n* bot0\n* bot1\n* bot2\n* bot3\n* bot4\n* bot5\n* bot6\n* bot7\n* bot8\n* bot9\nYou can take ownership of each bot by enabling it at **Integrations > Bot Accounts** and creating new tokens for the bot.\n\nFor more information, see our [documentation](https://docs.mattermost.com/developer/bot-accounts.html#what-happens-when-a-user-who-owns-bot-accounts-is-disabled)." , message )
// print all bots
th . App . UpdateConfig ( func ( cfg * model . Config ) { * cfg . ServiceSettings . DisableBotsWhenOwnerIsDeactivated = false } )
message = th . App . getDisableBotSysadminMessage ( user1 , userBots )
2020-03-02 15:57:29 -06:00
assert . Equal ( t , "user1_disabled was deactivated. They managed the following bot accounts which are still enabled.\n\n* bot0\n* bot1\n* bot2\n* bot3\n* bot4\n* bot5\n* bot6\n* bot7\n* bot8\n* bot9\n\nWe strongly recommend you to take ownership of each bot by re-enabling it at **Integrations > Bot Accounts** and creating new tokens for the bot.\n\nFor more information, see our [documentation](https://docs.mattermost.com/developer/bot-accounts.html#what-happens-when-a-user-who-owns-bot-accounts-is-disabled).\n\nIf you want bot accounts to disable automatically after owner deactivation, set “Disable bot accounts when owner is deactivated” in **System Console > Integrations > Bot Accounts** to true." , message )
2019-12-06 20:00:47 -06:00
// create additional bot to go over the printable limit
for i := numBotsToPrint ; i < numBotsToPrint + 1 ; i ++ {
bot , err = th . App . CreateBot ( & model . Bot {
Username : fmt . Sprintf ( "bot%v" , i ) ,
Description : "a bot" ,
OwnerId : user1 . Id ,
} )
require . Nil ( t , err )
userBots = append ( userBots , bot )
}
assert . Len ( t , userBots , 11 )
// truncate number bots printed
th . App . UpdateConfig ( func ( cfg * model . Config ) { * cfg . ServiceSettings . DisableBotsWhenOwnerIsDeactivated = true } )
message = th . App . getDisableBotSysadminMessage ( user1 , userBots )
assert . Equal ( t , "user1_disabled was deactivated. They managed 11 bot accounts which have now been disabled, including the following:\n\n* bot0\n* bot1\n* bot2\n* bot3\n* bot4\n* bot5\n* bot6\n* bot7\n* bot8\n* bot9\nYou can take ownership of each bot by enabling it at **Integrations > Bot Accounts** and creating new tokens for the bot.\n\nFor more information, see our [documentation](https://docs.mattermost.com/developer/bot-accounts.html#what-happens-when-a-user-who-owns-bot-accounts-is-disabled)." , message )
// truncate number bots printed
th . App . UpdateConfig ( func ( cfg * model . Config ) { * cfg . ServiceSettings . DisableBotsWhenOwnerIsDeactivated = false } )
message = th . App . getDisableBotSysadminMessage ( user1 , userBots )
2020-03-02 15:57:29 -06:00
assert . Equal ( t , "user1_disabled was deactivated. They managed 11 bot accounts which are still enabled, including the following:\n\n* bot0\n* bot1\n* bot2\n* bot3\n* bot4\n* bot5\n* bot6\n* bot7\n* bot8\n* bot9\nWe strongly recommend you to take ownership of each bot by re-enabling it at **Integrations > Bot Accounts** and creating new tokens for the bot.\n\nFor more information, see our [documentation](https://docs.mattermost.com/developer/bot-accounts.html#what-happens-when-a-user-who-owns-bot-accounts-is-disabled).\n\nIf you want bot accounts to disable automatically after owner deactivation, set “Disable bot accounts when owner is deactivated” in **System Console > Integrations > Bot Accounts** to true." , message )
2019-12-06 20:00:47 -06:00
}
2019-05-06 07:59:51 -07:00
func TestConvertUserToBot ( t * testing . T ) {
t . Run ( "invalid user" , func ( t * testing . T ) {
t . Run ( "invalid user id" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
_ , err := th . App . ConvertUserToBot ( & model . User {
Username : "username" ,
Id : "" ,
} )
require . NotNil ( t , err )
require . Equal ( t , "model.bot.is_valid.user_id.app_error" , err . Id )
} )
t . Run ( "invalid username" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
_ , err := th . App . ConvertUserToBot ( & model . User {
Username : "invalid username" ,
Id : th . BasicUser . Id ,
} )
require . NotNil ( t , err )
require . Equal ( t , "model.bot.is_valid.username.app_error" , err . Id )
} )
} )
t . Run ( "valid user" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
bot , err := th . App . ConvertUserToBot ( & model . User {
Username : "username" ,
Id : th . BasicUser . Id ,
} )
require . Nil ( t , err )
defer th . App . PermanentDeleteBot ( bot . UserId )
assert . Equal ( t , "username" , bot . Username )
assert . Equal ( t , th . BasicUser . Id , bot . OwnerId )
} )
}
2019-07-11 12:00:12 -04:00
func TestSetBotIconImage ( t * testing . T ) {
t . Run ( "invalid bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
path , _ := fileutils . FindDir ( "tests" )
svgFile , fileErr := os . Open ( filepath . Join ( path , "test.svg" ) )
require . NoError ( t , fileErr )
defer svgFile . Close ( )
err := th . App . SetBotIconImage ( "invalid_bot_id" , svgFile )
require . NotNil ( t , err )
} )
t . Run ( "valid bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
// Set an icon image
path , _ := fileutils . FindDir ( "tests" )
svgFile , fileErr := os . Open ( filepath . Join ( path , "test.svg" ) )
require . NoError ( t , fileErr )
defer svgFile . Close ( )
expectedData , fileErr := ioutil . ReadAll ( svgFile )
require . Nil ( t , fileErr )
require . NotNil ( t , expectedData )
bot , err := th . App . ConvertUserToBot ( & model . User {
Username : "username" ,
Id : th . BasicUser . Id ,
} )
2019-10-03 18:15:27 +05:30
require . Nil ( t , err )
2019-07-11 12:00:12 -04:00
defer th . App . PermanentDeleteBot ( bot . UserId )
fpath := fmt . Sprintf ( "/bots/%v/icon.svg" , bot . UserId )
exists , err := th . App . FileExists ( fpath )
require . Nil ( t , err )
require . False ( t , exists , "icon.svg shouldn't exist for the bot" )
svgFile . Seek ( 0 , 0 )
err = th . App . SetBotIconImage ( bot . UserId , svgFile )
require . Nil ( t , err )
exists , err = th . App . FileExists ( fpath )
require . Nil ( t , err )
require . True ( t , exists , "icon.svg should exist for the bot" )
actualData , err := th . App . ReadFile ( fpath )
require . Nil ( t , err )
require . NotNil ( t , actualData )
require . Equal ( t , expectedData , actualData )
} )
}
func TestGetBotIconImage ( t * testing . T ) {
t . Run ( "invalid bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
actualData , err := th . App . GetBotIconImage ( "invalid_bot_id" )
require . NotNil ( t , err )
require . Nil ( t , actualData )
} )
t . Run ( "valid bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
// Set an icon image
path , _ := fileutils . FindDir ( "tests" )
svgFile , fileErr := os . Open ( filepath . Join ( path , "test.svg" ) )
require . NoError ( t , fileErr )
defer svgFile . Close ( )
expectedData , fileErr := ioutil . ReadAll ( svgFile )
require . Nil ( t , fileErr )
require . NotNil ( t , expectedData )
bot , err := th . App . ConvertUserToBot ( & model . User {
Username : "username" ,
Id : th . BasicUser . Id ,
} )
2019-10-03 18:15:27 +05:30
require . Nil ( t , err )
2019-07-11 12:00:12 -04:00
defer th . App . PermanentDeleteBot ( bot . UserId )
svgFile . Seek ( 0 , 0 )
fpath := fmt . Sprintf ( "/bots/%v/icon.svg" , bot . UserId )
_ , err = th . App . WriteFile ( svgFile , fpath )
require . Nil ( t , err )
actualBytes , err := th . App . GetBotIconImage ( bot . UserId )
require . Nil ( t , err )
require . NotNil ( t , actualBytes )
actualData , err := th . App . ReadFile ( fpath )
require . Nil ( t , err )
require . NotNil ( t , actualData )
require . Equal ( t , expectedData , actualData )
} )
}
func TestDeleteBotIconImage ( t * testing . T ) {
t . Run ( "invalid bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
err := th . App . DeleteBotIconImage ( "invalid_bot_id" )
require . NotNil ( t , err )
} )
t . Run ( "valid bot" , func ( t * testing . T ) {
th := Setup ( t ) . InitBasic ( )
defer th . TearDown ( )
// Set an icon image
path , _ := fileutils . FindDir ( "tests" )
svgFile , fileErr := os . Open ( filepath . Join ( path , "test.svg" ) )
require . NoError ( t , fileErr )
defer svgFile . Close ( )
expectedData , fileErr := ioutil . ReadAll ( svgFile )
require . Nil ( t , fileErr )
require . NotNil ( t , expectedData )
bot , err := th . App . ConvertUserToBot ( & model . User {
Username : "username" ,
Id : th . BasicUser . Id ,
} )
2019-10-03 18:15:27 +05:30
require . Nil ( t , err )
2019-07-11 12:00:12 -04:00
defer th . App . PermanentDeleteBot ( bot . UserId )
// Set icon
svgFile . Seek ( 0 , 0 )
err = th . App . SetBotIconImage ( bot . UserId , svgFile )
require . Nil ( t , err )
// Get icon
actualData , err := th . App . GetBotIconImage ( bot . UserId )
require . Nil ( t , err )
require . NotNil ( t , actualData )
require . Equal ( t , expectedData , actualData )
// Bot icon should exist
fpath := fmt . Sprintf ( "/bots/%v/icon.svg" , bot . UserId )
exists , err := th . App . FileExists ( fpath )
require . Nil ( t , err )
require . True ( t , exists , "icon.svg should exist for the bot" )
// Delete icon
err = th . App . DeleteBotIconImage ( bot . UserId )
require . Nil ( t , err )
// Bot icon should not exist
exists , err = th . App . FileExists ( fpath )
require . Nil ( t , err )
require . False ( t , exists , "icon.svg should be deleted for the bot" )
} )
}
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 07:06:45 -08:00
func sToP ( s string ) * string {
return & s
}