Commit Graph

263 Commits

Author SHA1 Message Date
Jesse Hallam
72448d12a9 deprecate timezones.json (#10311) 2019-02-25 12:07:45 -04:00
Daniel Schalla
f046163a12 [MM-13840] Change eMail as a post-verification action (#10253)
* Change eMail as a post-verification action

* Fix broken test

* comment for special behavior, tests

* govet

* Check for already existent eMails when require email verification is turned on before accepting update
2019-02-20 15:50:52 +01:00
Sandeep Sukhani
29060acb45 [MM-13828] Initialize tests in each package with a new temp folder with all test resources (#10261)
* [MM-13828] Running tests from a new temp folder with all test resources

Possible fix for #10132

All packages which have a TestMain and use testlib.MainHelper will have a new current working directory which will have all the test
resources copied.

Note: default.json is copied as config.json as well to make sure tests don't have any impact due to changes in config by devs

* [MM-13828] Added TestMain to remaining packages to use testlib.MainHelper

This makes sure tests from all packages run with same test resources, setup in a new temp folder for each package

* Updated Jenkins file to not not config/default.json

This makes sure CI has same config files as a dev's machine

* [MM-13828] Changes requested from code review

Added accessor methods to testlib.MainHelper for accessing members
Fixed some broken tests due to change in cwd while tests run
Some other code refactoring and improvements

* [MM-13828] Added new factory method with options for creating test main helper and some code refactoring

testlib.NewMainHelperWithOptions supports options to turn on/off test dependencies and environment setup
Some other code refactoring

* Exporting members of testlib.MainHelper to make enterprise tests work

* Fixed gofmt error

* [MM-13828] removed unwanted dependency on plugins directory while setting up test resources

* [MM-13828] Fixed some tests failing due to them being running from temp folder

* [MM-13828] Some code changes suggested in PR review

* Fixed gofmt error
2019-02-19 09:20:11 -05:00
Adzim Zul Fahmi
f4249b5456 [MM-12304] Add channel search support in mattermost cli (#10093)
#### Summary
add command search on channel group.
it could search channel by name or id in general
and search channel with team by team name or id

#### Ticket Link
Fixes https://github.com/mattermost/mattermost-server/issues/9491
https://mattermost.atlassian.net/browse/MM-12304

#### Checklist
- [x] Added or updated unit tests (required for all new features)
2019-02-19 07:42:30 +01:00
Jesse Hallam
9bf5687311 MM-11262: database config store (#10281)
* vendor github.com/jmoiron/sqlx

* MM-11262: introduce a database store

* revert unnecessary fmt.Errorf

* simplify unit test helper methods

* remote TODO re: retry

* relocate initializeConfigurationsTable for clarity

* factor out a commonStore

* acquire database config lock on close for safety

* add missing header

* fix lock comment
2019-02-15 10:05:29 -04:00
Jesse Hallam
285b646d67 MM-13893: introduce file store (#10243)
* config file store

Introduce an interface and concrete implementation for accessing the config.

This mostly maps 1:1 with the exiting usage in `App`, except for internalizing the watcher. A future change will likely eliminate `App.PersistConfig()` and make this implicit on `Set` or `Patch`

* experimental file test changes

* emoji: move file driver checks from api4 to app

It is no longer possible to app.UpdateConfig and provide an invalid configuration, making it hard to test this case. This check doesn't really belong in the api anyway, since it's a configuration validity check and not a permissions check. Either way, the check now occurs at the App level.

* api4: generate valid public link salts for test

* TestStartServerRateLimiterCriticalError: use mock store to test invalid config

* remove config_test.go

* remove needsSave, and have Load() save to the backing store as necessary

* restore README.md

* move ldap UserFilter check to model isValid checks

* remove databaseStore until ready

* remove unimplemented Patch

* simplify unlockOnce implementation

* revert forgetting to set s.Ldap

* config/file.go: rename ReadOnlyConfigurationError to ErrReadOnlyConfiguration

* config: export FileStore

* add TestFileStoreSave

* improved config/utils test coverage

* restore config/README.md copy

* tweaks

* file store: acquire a write lock on Save/Close to safely close watcher

* fix unmarshal_test.go
2019-02-12 10:19:01 -08:00
Jesse Hallam
3a71709103 MM-13893: refactor config (#10230)
* refactor utils/config* to config/

* pull validateLdapFilter into app

* clean up Config/GetConfig/GetSanitizedConfig usage

Eliminate app.GetConfig() in favour of just using app.Config() directly,
but expose app.GetSanitizedConfig() for when the old behaviour was
required.

* web: isolate config setup

* TestInvitePeopleProvider: make config explicit

* regenerateClientConfig: avoid racey map access

* integrate watch flag into app.ConfigFile option

* make app.Option return an error

* release.mk: only cp static files from config/

* release.mk: fix cp static files from config/

* api4: TestPlugin cleanup

* s/c/cfg/ for clarity

* fix merge conflict

* testlib: allow customization of testlib driver name
2019-02-12 08:37:54 -05:00
Carlos Tadeu Panato Junior
86aa01cf36 fix test (#10212) 2019-01-31 13:07:49 -04:00
Joram Wilander
2ca222033c MM-10658 Change config fields to pointers (#9033)
* MM 10658 Change config fields to pointers (#8898)

* Change fields of config structs to pointers and set defaults

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Fix tests that go broken during switching config structs to pointers

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Apply changes of current master while switching config structs to pointers

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Fix new config pointer uses

* Fix app tests

* Fix mail test

* remove debugging statement

* fix TestUpdateConfig

* assign config consistently

* initialize AmazonS3Region in TestS3TestConnection

* initialize fields for TestEmailTest

* fix TestCheckMandatoryS3Fields
2019-01-31 08:12:01 -05:00
Deep Vora
cd30a1f242 MM-12375 added webhook show command (#10123)
MM-12375 added tests for webhook show command
2019-01-31 11:07:42 +00:00
Hanzei
d898787371 Fix shadowed variables in various places: Part 1 of 2 (#10175)
* Fix shadowed variables in cmd package

* Fix shadowed variables in plugin package

* Fix shadowed variables in store package

* Fix shadowed variables in web package

* Changes as requested

Signed-off-by: Hanzei <hanzei@mailbox.org>

* Fix build

* Remove unnessary statements

* Use require all the time

* Fix build

* Rename variables according to feedback

* Fix NPE

* Changes as requested
2019-01-30 12:55:24 -05:00
Gabriel Jackson
58ef6853f1 MM-12359 Add 'command show' CLI command (#10073)
* MM-12359 Add 'command show' CLI command

This new CLI command prints out the detailed information of a given
slash command.

* Fix typo in error returned when moving slash commands

* Move prettyPrint CLI functions to util

* Move prettyPrint CLI tests to util
2019-01-29 08:01:24 +01:00
Miguel de la Cruz
48048f9e95 Starts Elasticsearch and Metrics when running the server. (#10182) 2019-01-28 08:27:46 -08:00
Ashutosh Kumar
9b952dce27 Team restore cli command (#9551)
Adds cli for team restore and team archive.
2019-01-28 13:04:19 +01:00
Carlos Tadeu Panato Junior
94e45c3466 add output when creating users using CLI (#10140)
* add output when creating users using CLI

* update per feedback

* update per feedback 2
2019-01-26 17:28:35 +01:00
Carlos Tadeu Panato Junior
0ed9fad78c add output when creating channel using cli (#10138)
* add output when creating channel using cli

* update per feedback
2019-01-26 17:08:21 +01:00
Carlos Tadeu Panato Junior
244e1a5a7a add output when creating webhooks with the CLI (#10139)
* add output when creating webhooks with the CLI

* update per feedback

* update per feedback
2019-01-25 09:39:43 -08:00
Christopher Speller
ae76d27b7d Migrate cluster to use Server struct directly. (#10101) 2019-01-15 09:09:25 -08:00
Miguel Alatzar
6b59ab4ee8 [MM 12373] Create CLI command "webhook modify-outgoing" (#10028)
* Add test for modifying outgoing webhook

* Add command to modify an outgoing webhook

* Use updated test helper

* Use errors.Wrap

* Lower case error strings and use fmt.Errorf

* Clone webhook into updatedHook

* Rename error variables
2019-01-08 14:10:19 -05:00
Christopher Speller
daa6c4172a Fixing first user being created with system admin privilages without being explicity specified. (#10014) 2019-01-02 07:29:08 -08:00
Christopher Speller
8429add371 Cleanup related to context refactor (#9988) 2018-12-17 08:51:46 -08:00
Jesse Hallam
86fa3866c1 Speed up build (#9993)
* configure MySQL to use tmpfs

* simplify use of COMPOSE_PROJECT_NAME, and set envs vs. overriding config.json, fix error output, --no-ansi

* cmd/mattermost/commands/*_test.go: ignore MM_SQLSETTINGS_DATASOURCE from the env

* clean up exit 1 semantics
2018-12-13 16:29:47 -05:00
Jesse Hallam
d39d9a5caf Dockerized build updated tests (#9943)
* testlib: introduce and leverage

This doesn't yet factor out the individual test helpers: many packages
still rely on `api4` directly to do this, but now wire up the test store
setup through this package. `app` and `store`, in particular, don't use
`testlib` because of circular dependencies at the moment.

* cmd: command_test.go: use api4 testlib

* cmd: plugin_test.go: remove dependence on test-config.json

* cmd: config_test.go use configured database settings

* ensure test-(te|ee) exit with status code

* test-server: run all tests, deprecating test-te/test-ee

* cmd/mattermost/commands: fix unit tests

Instead of relying on (and modifying) a config.json found in the current path, explicitly create a temporary one from defaults for each test. This was likely the source of various bugs over time, but specifically allows us to override the SqlSettings to point at the configured test database for all tests simultaneously.

* wrap run/check into a test helper

It was insufficient to set a config for each invocation of CheckCommand or RunCommand: some tests relied on the config having changed in a subsequent assertion. Instead, create a new test helper embedding api4.TestHelper. This has the nice advantage of cleaning up all the teardown.

* additional TestConfigGet granularity

* customized config path to avoid default location

* be explicit if the storetest initialization fails

* generate safe coverprofile names in the presence of subtests

* additional TestConfigShow granularity

* fix permission_test.go typo

* fix webhook tests

* actually flag.Parse() to skip database setup on os.Execed tests

* fix recent regression in #9962, not caught by unit tests
2018-12-06 13:19:32 -05:00
Jesse Hallam
a317093467 leverage CheckCommand when a cmd should pass (#9944)
Using RunCommand obscures the error if, indeed, the assertion fails because the cmd fails to run.
2018-12-05 10:51:31 -08:00
Jesús Espino
6a2f81601d Commenting out delete command test becase race condition (#9952) 2018-12-04 20:36:53 +01:00
Jesús Espino
105fc4b38d Fixing weird fail on delete command tests (#9937) 2018-12-04 12:36:58 +01:00
Jesús Espino
2611606e13 Improved how CLI "command delete" command works (#9929) 2018-12-04 06:13:37 +01:00
Jesús Espino
adedb44925 Validating config on set command (#9914)
* Validating config on set command

* Adding more tests to confg set command
2018-12-03 14:18:05 +01:00
Jesús Espino
ba0a9b4d50 MM-12368: Fixing webhook create incomming (#9905) 2018-11-29 11:49:45 +01:00
Christopher Speller
da265fbaf7 Moving app from singular to being created for every request (#9889)
* Moving app from singular to being created for every request.

* Automatic refactor

* Adding license header

* Feedback fixes
2018-11-28 10:56:21 -08:00
Jesús Espino
415036ee8d Improving create-outgoing webhook command (#9899) 2018-11-28 15:55:16 +01:00
Harshit Patni
7663de06bb [MM - 12370] Add cli command "webhook delete" (#9804)
* [MM - 12370] Add cli command "webhook delete"

* Replace spaces with tabs

* Call cli command to delete hooks in tests

* Capture webhook object from create webhook to get webhook id

* Print error message when webhook not deleted

* Remove redundant error message and if condition in webhook delete test

* Fix build
2018-11-26 12:32:11 +01:00
Jesse Hallam
a78913178c Ensure unittest isolation (#9819)
* api4: fix TestGetUsersNotInTeam assertions

This test was relying on data from a previous test run. With the data cleared before each test, the assertions much match reality.

* *testlib: always InitSystemAdmin

Some tests implicitly relied on the basic user having system
administrator privileges because it was the first user created as such.
Eliminate `InitSystemAdmin` and explicitly create the system admin user
instead to avoid this ambiguity going forward.

* *testlib: drop all tables before each test

* api4: split up TestChannelDelete to avoid duplicate InitBasic

* api4: teardown in TestResetPassword, for when this test comes back

* invalidate cache on DropAllTables

This is necessary since the test store persists across tests.

* disable parallel tests

While tests within a package must be explicitly parallelized using `t.Parallel()`, tests across packages are run in parallel by default.  This causes problems given that the tests all currently share the same database instance.

Unfortunately, this also means that running the tests is much slower, but we can return to this later.
2018-11-20 20:16:25 -05:00
Wasim Thabraze
246ff89391 MM-12463 : Added capability to bulk export custom emojis (#9790) 2018-11-19 14:43:31 +00:00
Daniel Fiori
8d56fcf568 Add library and command for human-readable logs (#9809)
* Update logrus to 1.2 and add as a direct dependency

* Create an mlog/human package for pretty-printing logs

This package can read JSON logs from mattermost.log, and output the data to
either logrus or a custom formatter, to make the logs more human readable.

* Create a command for outputting human-readable logs

This command will read JSON data from mattermost.log or stdin, and
output in a human readable format. An optional argument can be used
to activate logrus output (which includes color support).

* Reorganize code in mlog/human and improve logrus timestamp formatting
2018-11-08 10:23:07 -08:00
Christopher Speller
ecade2f1ec MM-12849 Moving all non request scoped items to Server struct (#9806)
* Moving goroutine pool

* Auto refactor

* Moving plugins.

* Auto refactor

* Moving fields to server

* Auto refactor

* Removing siteurl duplication.

* Moving reset of app fields

* Auto refactor

* Formatting

* Moving niling of Server to after last use

* Fixing unit tests.
2018-11-07 10:20:07 -08:00
Wasim Thabraze
0dcbecac87 Added MinimumNArgs to required commands in channels.go and team.go (#9792)
Removed arguments length comparison as MinimumNArgs would handle it.

Addressed code review
2018-11-06 11:20:49 +00:00
Christopher Speller
418a0ec10e Fixing formatting. (#9801) 2018-11-06 16:28:55 +08:00
Jason Mojica
1aa3ceccc2 MM-12355: Add CLI command "command create" revision (#9734)
* Check for admin only setting and user admin status.

If "EnableOnlyAdminIntegrations" is true, will only allow team admins
to create slash commands

* Add test for non-admin user

* Simplify permissions check

* Change error message

* Fix test
2018-11-05 14:55:31 +00:00
Kerry Dougherty
c155359e58 MM-12369 Add Create Outgoing Webhook Command (#9779)
* add create outgoing webhook command

* add create outgoing webhook command
2018-11-02 13:39:38 -04:00
George Goldberg
8d3cfc6ad7 MM-12815: Clearly deprecated disused config settings. (#9751)
* MM-12815: Clearly deprecated disused config settings.

* Fix tests.
2018-10-31 08:38:38 +00:00
Mukul Rawat
2b6d6acb78 [MM-12361] Create CLI-command "config set" (#9535) (#9582)
* Create the config set command in the variable

* Register the command and declare the command in the run function

* Finish implementation of 'config set' cli command

* Write tests for config set command

* Change minimum number of arguments to 2

* Correct changes

* Correct error problem

* Update the command description and errors

* Refactor function name and improve error messages

* Write test for UpdateMap function
2018-10-29 09:29:15 +00:00
Shobhit Gupta
c317d6f265 MM-12356 Add cli command "command delete" (#9553)
* Add cli command for deleting commands

* Add code/test for delete command

* Fix test

* Add confirm flag

* Update as per comments

* Uncomment test

* Fix test
2018-10-23 12:19:10 +01:00
Artur Mogozov
c3993704ef MM-12372 Add modify-incoming webhook command (#9683)
* MM-12372 Add modify-incoming webhook command

* Review comments
2018-10-19 12:04:12 +01:00
Artur Mogozov
cedf6488e4 MM-12368 Add create webhook-incoming command (#9566) 2018-10-16 12:13:00 +01:00
Mukul Rawat
80153ef873 [MM-12362] Add CLI command 'config show' (#9536) (#9564)
* Add the subcommand by creating a new Command instance.

* Implemented the structure of the subcommand function.

* Register our new command

* Write some helper functions

* finish the pretty print function

* write some test for config show

* Refactor and extract the tab printing functionality in its own function

* Use app.Config() to create our config object & accept incoming changes

* Removed reading the file, make helper functions return string and perform printing inside the command

* Remove the previous code for checking presence of arguments and use 'cobra.NoArgs()' instead

* Remove named return and instead declare the variable and then return it.

* Remove printTab function and simplify printing out tabs using strings.Repeat

* Add some functions to test the output

* Update the usage and remove a comment

* Update the print
2018-10-15 18:06:46 -04:00
Wasim Thabraze
457a34c5f4 [MM-12363] Added Team archive command to archive a team by name (#9565)
* Added Team archive command to archive a team by name

* Team archive command now uses SoftDelete method

Team search and list command now shows archived teams with the term '(archived)' appended to them
2018-10-15 19:48:18 +01:00
Mukul Rawat
9385dc750d [MM-12360] Created CLI command "config get" (#9534) (#9558)
* Added the get command to get the value of a config setting.

* Depending on the config setting it can work on any depth of the
setting.

* Added test for the get command.

* Add print tabs

* Remove excess else statements

* Return with the value and remove named return variable

* Refactor the printMap function and return a string, remove side effects

* Improve the error message, use the name argument

* Use app.Config() to create our config object

* Remove reading the file, make helper functions return string and perform printing inside the command

* Remove the tab printing

* Add extra quotes on the output

* Remove extra code for checking arguments and replaced it with cobra.ExactArgs(1)

* Remove buffer from printConfigValues

* Add some tests to check the output of the command

* Write test for the function 'structToMap' and test for complext nested structs

* Write test for the function 'configToMap' and test for complext nested structs

* Write test for the function 'printMap' and test for complext maps as input

* Write test for the function 'printConfigValues' and test for complext maps as input

* Remove commented code

* Update the description of the  command
2018-10-15 10:49:25 -04:00
Jason Mojica
f025e749a9 MM-12355: Add CLI command "command create" (#9569)
* Add create command

* Create CreateCommand Tests

* Change method flag description

* Change nil test assertion
2018-10-13 13:35:00 +01:00
George Goldberg
9a4f3ce1e5 MM-12251: Add flag to MoveChannel to remove all deactivated users. (#9515) 2018-10-08 16:39:03 +01:00