Commit Graph

12355 Commits

Author SHA1 Message Date
Juho Nurminen
cf3ba6661d Fix dependency alerting (#14457)
Automatic Merge
2020-05-04 04:21:47 -07:00
Doug Lauder
a6a58f99e7 MM-24707 fix reply import bug (#14442) 2020-05-01 14:13:06 -04:00
Agniva De Sarker
4f022aff6d MM-24547: Fix writer leak when connection closes (#14406)
* MM-24547: Fix writer leak when connection closes

When the connection is closed, the exit path does not
shut down the writer goroutine. In which case, it will keep spinning forever.

Since we already have the CAS mechanism now, we can move the closing
functionality into the main Close method and just call that in the defer block.

This makes closing the websocket client idempotent from both perspective -
- Explicitly closing.
- Closing due to connection tear down.

There are still 2 races left:
- Using the exported Conn to directly write messages. We cannot do anything about
that as long as clients directly using that.
- Setting the wsc.pingTimeoutTimer field in a separate goroutine when calling
.Connect(). This will need to be seen later.

* Fix ineffectual assignment

* Duplicate the closing of writer

The problem with refactoring the writer closing to a common
function was that we needed to wait for the reader to exit
before closing the EventChannel and ResponseChannel.

But then there is another problem that the API can be used in such
a way that the client is liable to call Close without even calling
Listen. In that case, we cannot wait for Listen to quit.

So from Close, we can only close the connection. And therefore
we need to duplicate the writer closing in the read loop's
defer block.

* Cleanup some comments
2020-04-30 23:50:13 +05:30
Eli Yukelzon
7800116429 MM-23093 Implement Server Setup telemetry - server configuration (#14374)
* added advanced first day diagnostics reporting

* typo

* config corrected

* defaults

* moved from config to system db table

* missing file

* added error handling

* tests

* typos

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-30 18:18:12 +03:00
Mario de Frutos Dieguez
278c295869 Move Rolestore.GetByNames query to raw query (#14403)
Given that this query is part of the top 5 most used queries
we want to move it to use raw queries instead of gorp so we
can get rid of the reflection overhead
2020-04-30 16:28:59 +02:00
Agniva De Sarker
5cb16c9fc7 MM-24395: Set response header to be attachment for SVG images. (#14385)
* MM-24395: Set response header to be attachment for SVG images.

We check the file extension and appropriately set the response header.
SVG images without a file extension aren't proxied at all. So there's no
problem with that.

* Add test

* Improve test a bit

* Capture content type

* incorporate comments

* Set attachment mode in case of error too
2020-04-30 09:03:13 +05:30
Agniva De Sarker
03a55367d9 MM-24312: Fix Dependency updates (#14391)
Automatic Merge
2020-04-29 14:06:09 -07:00
Doug Lauder
a3cf490a4d MM-24575 handle auto-respond to self (#14410) 2020-04-29 14:19:18 -04:00
Miguel de la Cruz
f85cbf6b5c Refactor audit_store to use squirrel (#14393)
* Refactor audit_store to use squirrel

* Add query build error translation
2020-04-29 16:18:27 +02:00
Juho Nurminen
6b99d68818 Suppress jQuery issue in Dependency-Check (#14396) 2020-04-29 10:38:19 +03:00
Christopher Speller
68ff87708a Update restricted team names. (#14386) 2020-04-28 07:37:19 -07:00
Agniva De Sarker
f0eb0a9a01 MM-24397: Reusing the read buffer while reading messages from websockets (#14368)
* MM-24397: Reusing the read buffer while reading messages from websockets

The core problem was that conn.ReadMessage allocated a buffer every time it was read.
This created heavy amount of allocations every single time we read a message from the websocket.

To avoid this, we bypass the ReadMessage which was more of a helper method,
and actually call the NextReader which returns a reader object.
We can then reuse a single byte.Buffer instance to read the object unmarshal
into a WebSocketEvent object. This gets rid of the allocation in the read path completly
and allows GC more time to do other tasks.

* Incorporate review comments

* Move reset buffer to top of loop

* Cleanup further

* Fix test

* Final fix
2020-04-28 19:38:11 +05:30
Jesús Espino
8781c36eb3 Fixing system messages about non-visible users (#14254)
* Fixing system messages about non-visible users

* Adding unit tests to verify the new behavior

* Regenerating app layers

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-28 12:58:34 +02:00
Jesús Espino
224b72c61e MM-24037 Adding getKnowUsers API endpoint (#14332)
* Adding getKnowUsers API endpoint

* Adding i18n strings

* Fixing golint errors

* Adding doc strings

* Remove debug line

* Updating app_iface

* Fixing gofmt
2020-04-28 12:52:43 +02:00
Agniva De Sarker
d3b36e3455 app: outdent skipSend condition (#14377)
We invert the skipSend condition and outdent the remaining block
to make the code a bit more idiomatic.

While here, we also change the dropping message level from info to
warn because that's what it should be.
2020-04-28 15:27:58 +05:30
Nev Angelova
6362926b5c [MM-23827] - Update nps plugin version (#14369)
Co-authored-by: Nevyana Angelova <nevyangelova@Nevyanas-MBP.fritz.box>
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-28 10:54:07 +02:00
Mario de Frutos Dieguez
9853056b7a Implementation of expectation tests (#14191) 2020-04-27 21:54:46 +02:00
Agniva De Sarker
f79b7567b1 MM-23896: Fix clearing of batched emails on user activity (#14340)
On user activity, we were clearing the job.pendingNotifications map.
But we had already created a copy of the notifications slice while
iterating the map. Therefore, if we pass the copied slice, it would
still have the old notifications which were originally deleted.

The unit tests would not catch this because it was testing the
job.pendingNotifications map and not actually checking if the email
handler was being called or not. We fix that now.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-28 00:59:48 +05:30
Farhan Munshi
b29b70da09 MM-23605 Create new team scheme updated socket event (#14305) 2020-04-27 13:26:52 -04:00
Farhan Munshi
7bc630a600 [MM-23727] Make channel validation consistent on the server (#14230)
* MM-23727 Ensure user ids not allowed in channel name:

MM-23727 Move channel name validation to model level

* MM-23727 Update wording
2020-04-26 12:38:33 -04:00
Farhan Munshi
036f9384b4 [MM-23264] Get channel member counts by group (#14068)
* MM-23264 Add api endpoint for get groups with members in channel

Add store tests

Add tests for api func

Gofmt

Apply changes from code review

* MM-23264 Make store layers

* MM-23264 Check read permission on channel member counts

* Trigger CI
2020-04-24 17:12:54 -04:00
Agniva De Sarker
e39569b358 MM-23805: Refactor web_hub (#14277)
* MM-23800: remove goroutineID and stack printing

Each hub has a goroutineID which is calculated with a known hack.
The FAQ clearly explains why goroutines don't have an id:
https://golang.org/doc/faq#no_goroutine_id.

We only added that because sometimes the hub would be deadlocked and
having the goroutineID would be useful when getting the stack trace.
This is also problematic in stress tests because the hubs would
frequently get overloaded and the logs would unnecessarily have stack traces.

But that was in the past, and we have done extensive testing with
load tests and fuzz testing to smooth any rough edges remaining.
Including adding additional metrics for hub buffer size.

Monitoring the metrics is a better way to approach this problem.
Therefore, we remove these kludges from the code.

* Also remove deadlock checking code

There is no need for that anymore since
we are getting rid of the stack printing anyways.

Let's do a wholesale refactor and clean up the codebase.

* MM-23805: Refactor web_hub

This is a beginning of the refactoring of the websocket code.

To start off with, we unexport some methods and constants which did not
need to be exported. There are more remaining but some are out of scope for this PR.

The main chunk of refactor is to unexport the webconn send channel
which was the main cause of panics. Since we were directly sending
to the connection from various parts of the codebase, it would be possible
that the send channel would be closed and we could still send a message.
This would crash the server.

To fix this, we refactor the code to centralize all sending from the main
hub goroutine. This means we can leverage the connections map to check
if the connection exists or not, and only then send the message.

We also move the cluster calls to cluster.go.

* bring back cluster code inside hub

* Incorporate review comments

* Address review comments

* rename index

* MM-23807: Refactor web_conn

- Unexport some struct fields and constants which are not necessary
to be accessed from outside the package. This will help us moving
the entire websocket handling code to a separate package later.

- Change some empty string checks to check for empty string rather
than doing a len check which is more idiomatic. Both of them compile
to the same code. So it doesn't make a difference performance-wise.

- Remove redundant ToJson calls to get the length.

- Incorporate review comments

- Unexport some more methods

* Fix field name

* Run make app-layers

* Add note on hub check
2020-04-23 13:16:18 +05:30
Claudio Costa
ad68af10df Increase entropy for MFA secret (#14290)
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-22 18:46:16 +02:00
Doug Lauder
50821d1a34 update github.com/minio/minio-go/v6 to v6.0.53 (#14349) 2020-04-23 00:15:06 +08:00
Jesse Hallam
636d168b84 MM-23926: avoid setting last viewed for bots (#14253)
The current code path for `CreatePostAsUser` tries to update the `LastViewedAt` for bots, which logs a warning message if the bot isn't actually in the channel.

This pull request changes the semantics of bot posting to not update the bot's `LastViewedAt` timestamp, avoiding this log altogether. It matches the semantics of `from_webhook`, but notably makes bots slightly less like users in that they no longer "read" channels when they post. This seems reasonable, but I'm both looking for validation of this semantic change in addition to the code review.

Fixes: https://mattermost.atlassian.net/browse/MM-23926

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-22 12:28:31 -03:00
Eli Yukelzon
d0dea3b19a API checker improvement (#14352)
Automatic Merge
2020-04-22 06:16:43 -07:00
Doug Lauder
d390942581 MM-24217 ensure updating Mfa secret and status invalidates cache (#14334) 2020-04-22 09:09:13 -04:00
Martin Kraft
70e9647e85 MM-23646: Improve group sync performance. (#14171)
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-21 15:55:30 -04:00
Agniva De Sarker
d9713792ba MM-23800: remove goroutineID and stack printing (#14268)
* MM-23800: remove goroutineID and stack printing

Each hub has a goroutineID which is calculated with a known hack.
The FAQ clearly explains why goroutines don't have an id:
https://golang.org/doc/faq#no_goroutine_id.

We only added that because sometimes the hub would be deadlocked and
having the goroutineID would be useful when getting the stack trace.
This is also problematic in stress tests because the hubs would
frequently get overloaded and the logs would unnecessarily have stack traces.

But that was in the past, and we have done extensive testing with
load tests and fuzz testing to smooth any rough edges remaining.
Including adding additional metrics for hub buffer size.

Monitoring the metrics is a better way to approach this problem.
Therefore, we remove these kludges from the code.

* Also remove deadlock checking code

There is no need for that anymore since
we are getting rid of the stack printing anyways.

Let's do a wholesale refactor and clean up the codebase.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-22 00:20:44 +05:30
Mario de Frutos Dieguez
9783294e97 Include dejavu in docker compose (#14329)
* Include dejavu in docker compose
2020-04-21 20:48:04 +02:00
Attila Molnar
f77ad4992b Fix assertExpectedWebsocketEvent ignoring the passed event (#14330) 2020-04-21 11:11:25 +02:00
George Goldberg
6cabc40e62 MM-23568: Add rudder to server diagnostics. (#14151)
* MM-23568: Add rudder to server diagnostics.

* Add unit test.

* Go mod tidy.

* CSP Header fix.

* Fix review comments.

* Update web/handlers.go

Co-Authored-By: Jesse Hallam <jesse.hallam@gmail.com>

* Partially address review comments.

* fix tests.

* Finish implementing review suggestions and then fixing tests.

* Fix CSP Header tests.

Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
2020-04-21 09:23:00 +01:00
Doug Lauder
26310720be MM-23724 add RestoreTeam endpoint (#14297)
* MM-23724 add RestoreTeam endpoint
* assert added to unit test
2020-04-20 22:40:22 -04:00
Doug Lauder
98c6401f54 MM-23722 add endpoint for modify team privacy (#14287)
* MM-23722 add Rest API for updating team privacy
* unit tests for UpdateTeamPrivacy
2020-04-20 21:09:40 -04:00
Jesús Espino
0cb8d96be2 Removing accidentally included debug log (#14310)
* Removing accidentally included debug log

* Regenerating the store layers
2020-04-20 14:37:11 +02:00
Carlos Tadeu Panato Junior
0d0ab51876 license: dropping PhoneNumber field from the license (#14307)
Per request of the bix team and checking the code this field is not used
in any place and also is one information that is not needed at all.
2020-04-20 14:20:35 +02:00
Mario de Frutos Dieguez
cff7de9e68 [MM-24065] Guest users should be able to search by channel (#14302)
* Remove unnecessary check for PERMISSION_LIST_TEAM_CHANNELS

In the autocompleteChannelsForTeamForSearch method we're checking for
the PERMISSION_LIST_TEAM_CHANNELS permission in order to avoid filtering
channels in the autocomplete search but this check is not necessary.

Now we're going directly to the database to search for those channels
in this specific method and we're filtering by channel membership and
team so there is no chance that we are going to filter undesired
channels to the user.

[Here](https://github.com/mattermost/mattermost-server/blob/v5.22.0/store/sqlstore/channel_store.go#L2014)
is the query where you can see the filtering we're making
2020-04-20 11:21:51 +02:00
Carlos Tadeu Panato Junior
176db1e189 dockerfile: set 5.22.0 version (#14309) 2020-04-18 11:00:13 +02:00
Jesse Hallam
4582823f87 fix /test command (#14169)
Automatic Merge
2020-04-18 00:08:57 -07:00
Farhan Munshi
e88ba85d60 [MM-23017] Add check for groups to SendNotifications (#14039)
* MM-23017 Check group mentions as part of notification logic

* Add nil groups to existing test cases

* MM-23017 Add tests for insertGroupMention and addGroupMention

* MM-23017 Add tests for getExplicitMentions that have groups

* Add tests for group store GetMemberUsersNotInChannel

* MM-23017 Add tests for AllowGroupMentions

* MM-23017 Fix error message name

* MM-23017 Swap Checks to Name

* MM-23017 Code review fixes

* Rename var and fix allowGroupMentions test

* MM-23017 Use GetMemberUsersInTeam inside of insertGroupMentions

* MM-23017 use group mentions permission

* Actually call GetMemberUsersInTeam

* Remove unnecessary new line

* Uncomment filter allow reference

* MM-23017 Fix group channel notifications

* Update store layer

* MM-23017 Improve test coverage for group channels

* Trigger CI

* Trigger CI
2020-04-17 19:22:54 -04:00
Jesse Hallam
29fae242e1 Revert "Dependency updates. (#14033)" (#14304)
This reverts commit f14c79f170.
2020-04-17 14:26:29 -03:00
Eli Yukelzon
be7ee97dd3 MM-24094 EnableOpenTracing config setting missing from teleme… (#14298) 2020-04-16 20:17:46 +03:00
Juho Nurminen
e763e308a4 Update Dependency-Check suppressions (#14294)
Automatic Merge
2020-04-16 09:38:57 -07:00
Flavia Bastos
d4132e783c Document sqlTeamStore analytics methods (#14300) 2020-04-16 17:57:33 +02:00
Jesús Espino
7ea637be10 MM-20934: Fixing int overflow in 32 bits on MaxImageSize check (#14280)
* MM-20934: Fixing int overflow in 32 bits on MaxImageSize check

* Adding comments explaining the casting and the bug fixed there

* Apply suggestions from code review

Co-Authored-By: Juho Nurminen <juhonurm@gmail.com>

* Fixing store layers

Co-authored-by: Juho Nurminen <juhonurm@gmail.com>
2020-04-16 15:23:27 +02:00
Doug Lauder
cd63c1153f MM-24096 add telemetry for audit log config (#14282)
* MM-24096 add telemetry for audit log config

* added audit config telemetry to unit test
2020-04-14 22:30:27 -04:00
Farhan Munshi
2a9f465bf2 Fix broken master build by updating store (#14291)
* Fix broken master build by updating store

* Run store-mocks
2020-04-14 16:24:30 -04:00
Mario de Frutos Dieguez
aafea55976 MM-23131 Include HTTP status code in the metrics (#14240)
* ResponseWriter wrapper to get status code

For our metrics, we need the status code returned by a request
so this wrapper includes a new method StatusCode() that includes
the desired code

* Shadow the responsewriter variable in the handlers

In order to avoid confusion to people deciding what variable to use.
I've also changed the tests to reflect this change and added a new
one that checks the Flush method works
2020-04-14 14:15:00 +02:00
Miguel de la Cruz
53c1c0d4b4 Add check-store-layers check to the CI and include their updates (#14264)
* Add check-store-layers check to the CI and include their updates

* Add check-store-layers as a dependency for the test tasks

* Remove changes to the store to avoid conflicts with https://github.com/mattermost/mattermost-server/pull/14261

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-04-13 22:58:03 +02:00
Ibrahim Serdar Acikgoz
eb5b04c86a app/diagnostics: add telemetry for smtp_server_timeout (#14283)
Automatic Merge
2020-04-13 12:08:57 -07:00