aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/mail_test.go
diff options
context:
space:
mode:
authorYury Smolsky <yury@smolsky.by>2018-03-21 01:23:00 +0200
committerBrad Fitzpatrick <bradfitz@golang.org>2018-03-30 21:38:54 +0000
commitfebe82b3542e335479ef0e8a401a0e95f070fa41 (patch)
treeb3d746400bde7ae847f6c7e8d00ca929c6ba06c5 /git-codereview/mail_test.go
parent34696713d8ce9c6e709a50d8192fd973246a30e9 (diff)
downloadgo-x-review-febe82b3542e335479ef0e8a401a0e95f070fa41.tar.xz
git-codereview: forbid mailing editor temp files
"mail" command rejects *~, #*# and .#* filenames. Also it should reject commit messages with non-printable characters, because these are impossible to spot in the review. For golang/go#24139 Change-Id: I3544e3c34c5ac9f55a7808264de4535bc455bd0a Reviewed-on: https://go-review.googlesource.com/101755 Run-TryBot: Yury Smolsky <yury@smolsky.by> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'git-codereview/mail_test.go')
-rw-r--r--git-codereview/mail_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/git-codereview/mail_test.go b/git-codereview/mail_test.go
index 8680f0e..b1b5201 100644
--- a/git-codereview/mail_test.go
+++ b/git-codereview/mail_test.go
@@ -57,6 +57,60 @@ func TestDoNotMail(t *testing.T) {
testPrintedStderr(t, "DO NOT MAIL")
}
+func TestDoNotMailTempFiles(t *testing.T) {
+ // fake auth information to avoid Gerrit error
+ auth.host = "gerrit.fake"
+ auth.user = "not-a-user"
+ defer func() {
+ auth.host = ""
+ auth.user = ""
+ }()
+
+ testFile := func(file string) {
+ gt := newGitTest(t)
+ defer gt.done()
+ gt.work(t)
+ gt.workFile(t, file)
+ testMainDied(t, "mail", "HEAD")
+ testPrintedStderr(t, "cannot mail temporary")
+ }
+
+ testFile("vim-backup.go~")
+ testFile("#emacs-auto-save.go#")
+ testFile(".#emacs-lock.go")
+
+ // Do not mail when a parent of the thing we asked to mail has temporary files.
+ gt := newGitTest(t)
+ defer gt.done()
+ gt.work(t)
+ gt.workFile(t, "backup~")
+ gt.work(t)
+ testMainDied(t, "mail", "HEAD")
+ testPrintedStderr(t, "cannot mail temporary")
+}
+
+func TestMailNonPrintables(t *testing.T) {
+ gt := newGitTest(t)
+ defer gt.done()
+ gt.work(t)
+
+ // fake auth information to avoid Gerrit error
+ auth.host = "gerrit.fake"
+ auth.user = "not-a-user"
+ defer func() {
+ auth.host = ""
+ auth.user = ""
+ }()
+
+ trun(t, gt.client, "git", "commit", "--amend", "-m", "This is my commit.\x10\n\n")
+ testMainDied(t, "mail")
+ testPrintedStderr(t, "message with non-printable")
+
+ // This should be mailed.
+ trun(t, gt.client, "git", "commit", "--amend", "-m", "Printable unicode: \u263A \u0020. Spaces: \v \f \r \t\n\n")
+ testMain(t, "mail", "HEAD")
+}
+
func TestMailGitHub(t *testing.T) {
gt := newGitTest(t)
defer gt.done()