From cbf8c16d735d6ff959e017b68022f5f35fa2b36d Mon Sep 17 00:00:00 2001 From: Michael Leonard Date: Fri, 20 Nov 2020 13:33:41 -0500 Subject: [PATCH] MM-T638 Webhook posts when webhook creator is not a member of the channel (#7091) * wip * wip * wip * wip * added check * small fix * fix Co-authored-by: Mattermod --- ..._posts_when_creator_not_in_channel_spec.js | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 e2e/cypress/integration/integrations/incoming_webhook/webhook_posts_when_creator_not_in_channel_spec.js diff --git a/e2e/cypress/integration/integrations/incoming_webhook/webhook_posts_when_creator_not_in_channel_spec.js b/e2e/cypress/integration/integrations/incoming_webhook/webhook_posts_when_creator_not_in_channel_spec.js new file mode 100644 index 000000000000..94bdcbf27dc2 --- /dev/null +++ b/e2e/cypress/integration/integrations/incoming_webhook/webhook_posts_when_creator_not_in_channel_spec.js @@ -0,0 +1,95 @@ + +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +// *************************************************************** +// - [#] indicates a test step (e.g. # Go to a page) +// - [*] indicates an assertion (e.g. * Check the title) +// - Use element ID when selecting an element. Create one if none. +// *************************************************************** + +// Group: @integrations + +import {getRandomId} from '../../../utils'; + +describe('Integrations', () => { + let testUser; + let secondUser; + let testTeam; + let testChannel; + let incomingWebhook; + + before(() => { + // # Create new setup + cy.apiInitSetup().then(({user}) => { + testUser = user; + + // # Create a second user + cy.apiCreateUser().then(({user: user2}) => { + secondUser = user2; + }); + + // # Login as the new user + cy.apiLogin(testUser).then(() => { + // # Create a new team with the new user + cy.apiCreateTeam('test-team', 'Team Testers').then(({team}) => { + testTeam = team; + + // # Add second user to the test team + cy.apiAddUserToTeam(testTeam.id, secondUser.id); + + // # Create a new test channel for the team + cy.apiCreateChannel(testTeam.id, 'test-channel', 'Testers Channel').then(({channel}) => { + testChannel = channel; + + const newIncomingHook = { + channel_id: testChannel.id, + channel_locked: true, + description: 'Test Webhook Description', + display_name: 'Test Webhook Name', + }; + + //# Create a new webhook + cy.apiCreateWebhook(newIncomingHook).then((hook) => { + incomingWebhook = hook; + }); + + // # Add second user to the test channel + cy.apiAddUserToChannel(testChannel.id, secondUser.id).then(() => { + // # Remove the first user from the channel + cy.apiDeleteUserFromTeam(testTeam.id, testUser.id).then(({data}) => { + expect(data.status).to.equal('OK'); + }); + + // # Login as the second user + cy.apiLogin(secondUser); + + // # Visit the test channel + cy.visit(`/${testTeam.name}/channels/${testChannel.name}`); + }); + }); + }); + }); + }); + }); + + it('MM-T638 Webhook posts when webhook creator is not a member of the channel', () => { + const payload = getPayload(testChannel); + + // # Post the webhook message + cy.postIncomingWebhook({url: incomingWebhook.url, data: payload}); + + // * Assert that the message was posted even though webhook author has been removed + cy.uiWaitUntilMessagePostedIncludes(payload.text); + cy.getLastPostId().then((postId) => { + cy.get(`#postMessageText_${postId}`).should('have.text', `${payload.text}`); + }); + }); +}); + +function getPayload(testChannel) { + return { + channel: testChannel.name, + text: `${getRandomId()} - this webhook was set up by a user that is no longer in this channel`, + }; +}