forked from projectdiscovery/notify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Escape password in smtp url (projectdiscovery#258)
* chore(deps): bump golang.org/x/net Bumps [golang.org/x/net](https://github.com/golang/net) from 0.0.0-20220909164309-bea034e7d591 to 0.7.0. - [Release notes](https://github.com/golang/net/releases) - [Commits](https://github.com/golang/net/commits/v0.7.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * ✅ Add failing test when password contains `#` Refactor smtp.Send by extracting the build of url to better test this part * 🐛 Escape password to return valid url --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
- Loading branch information
1 parent
258ca0a
commit a3e1e00
Showing
2 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package smtp | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
) | ||
|
||
// TestBuildUrl checks the output of buildUrl is valid and parsable by url.Parse | ||
func TestBuildUrl(t *testing.T) { | ||
options := &Options{ | ||
Server: "mail.example.com", | ||
Username: "test@example.com", | ||
Password: "password", | ||
FromAddress: "from@email.com", | ||
SMTPCC: []string{"to@email.com"}, | ||
Subject: "Email subject", | ||
} | ||
t.Run("with provider config example", func(t *testing.T) { | ||
u := buildUrl(options) | ||
_, err := url.Parse(u) | ||
if err != nil { | ||
t.Errorf("Failed to parse url: %s", err) | ||
} | ||
}) | ||
t.Run("with octohorpe in password", func(t *testing.T) { | ||
options.Password = "passwordwith#inside" | ||
u := buildUrl(options) | ||
_, err := url.Parse(u) | ||
if err != nil { | ||
t.Errorf("Failed to parse url: %s", err) | ||
} | ||
}) | ||
} |