Incorrect "Connection failed. Please check your settings." response in settings test of "Emails on push" integration

Summary

When using the "Protected branches" for the "Branches for which notifications are to be sent" setting in the "Emails on push" integration, the "Test settings" button incorrectly reports "Connection failed. Please check your settings." if the project's default branch is not protected.

The actual integration itself works correctly, emails are being sent as expected when the settings are saved despite the error. The error occurs both when no protected branches exist at all, but also when there are protected branches. Only if the default branch is added as a protected branch, the "Test settings" button will report "Connection successful."

Steps to reproduce

  1. Create new project
  2. Unprotect all branches
  3. Enable "Emails on push" integration
  4. Select "Protected branches" in "Branches for which notifications are to be sent" dropdown
  5. Enter valid email address
  6. Click "Test settings", observe "Connection failed. Please check your settings." message
  7. Create new branch in project and add it to protected branches
  8. Repeat step 6, still observing the same error message
  9. Add project default branch to protected branches
  10. Repeat step 6, now observe "Connection successful." message

Example Project

Other than a few settings and a branch there is nothing specific about the issue, but I'll provide the project I used to verify the issue occurs even on GitLab.com: https://gitlab.com/gitlab-gold/mg-gold/email-push-test

What is the current bug behavior?

The settings test reports "Connection failed. Please check your settings."

What is the expected correct behavior?

The settings test should report "Connection successful." if there are any protected branches, and maybe a specific "No protected branches exist." error if that is the case.

Relevant logs and/or screenshots

Protected branch exists, default branch not protected, incorrect error message

image

No protected branch exists at all, incorrect error message

image

Protected branch exists, default branch is also protected, correct message

image

Only default branch is protected, correct message

image

Output of checks

This bug happens on GitLab.com

Possible fixes

I think it might be somewhere in notify_for_branch(), which is being called from notify_for_ref(), which is being called from execute(). It looks to me like execute() is what is being used for the test based on test() in app/models/integration.rb. But those are all just fairly wild guesses.

Edited by 🤖 GitLab Bot 🤖