Mercurial > projects > managesieve
comparison managesieve_test.go @ 4:f9bb517e9447
Return warning messages from the CHECKSCRIPT and PUTSCRIPT commands
author | Guido Berhoerster <guido+managesieve@berhoerster.name> |
---|---|
date | Tue, 27 Oct 2020 17:47:14 +0100 |
parents | 6369453d47a3 |
children | b790df0733d4 |
comparison
equal
deleted
inserted
replaced
3:8413916df2be | 4:f9bb517e9447 |
---|---|
116 | 116 |
117 if envelope :contains "to" "tmartin+lists" { | 117 if envelope :contains "to" "tmartin+lists" { |
118 redirect "lists@groups.example.com"; | 118 redirect "lists@groups.example.com"; |
119 } | 119 } |
120 ` | 120 ` |
121 var expectedWarnings = "line 8: server redirect action limit is 2, this redirect might be ignored" | |
121 | 122 |
122 // basic functionality | 123 // basic functionality |
123 var basicServer string = `"IMPlemENTATION" "Example1 ManageSieved v001" | 124 var basicServer string = `"IMPlemENTATION" "Example1 ManageSieved v001" |
124 "SASl" "PLAIN DIGEST-MD5 GSSAPI" | 125 "SASl" "PLAIN DIGEST-MD5 GSSAPI" |
125 "SIeVE" "fileinto vacation" | 126 "SIeVE" "fileinto vacation" |
135 "StaRTTLS" | 136 "StaRTTLS" |
136 "NOTIFY" "xmpp mailto" | 137 "NOTIFY" "xmpp mailto" |
137 "MAXREdIRECTS" "5" | 138 "MAXREdIRECTS" "5" |
138 "VERSION" "1.0" | 139 "VERSION" "1.0" |
139 OK | 140 OK |
140 OK (WARNINGS) "line 8: server redirect action limit is 2, this redirect might be ignored" | 141 OK (WARNINGS) "` + expectedWarnings + `" |
141 OK | 142 OK |
142 OK (WARNINGS) "line 8: server redirect action limit is 2, this redirect might be ignored" | 143 OK (WARNINGS) "` + expectedWarnings + `" |
143 OK | 144 OK |
144 "default" ACTIVE | 145 "default" ACTIVE |
145 OK | 146 OK |
146 ` + quoteServerString(validScript) + ` | 147 ` + quoteServerString(validScript) + ` |
147 OK | 148 OK |
215 auth := managesieve.PlainAuth("", "foo", "S3cR3T", "localhost") | 216 auth := managesieve.PlainAuth("", "foo", "S3cR3T", "localhost") |
216 if err := c.Authenticate(auth); err != nil { | 217 if err := c.Authenticate(auth); err != nil { |
217 t.Fatalf("plain authentication failed: %s", err) | 218 t.Fatalf("plain authentication failed: %s", err) |
218 } | 219 } |
219 | 220 |
220 if err = c.CheckScript(validScript); err != nil { | 221 if warnings, err := c.CheckScript(validScript); err != nil { |
221 t.Fatalf("CHECKSCRIPT failed: %s", err) | 222 t.Fatalf("CHECKSCRIPT failed: %s", err) |
223 } else if warnings != expectedWarnings { | |
224 t.Fatalf("CHECKSCRIPT expected: %s, got %s", warnings, | |
225 expectedWarnings) | |
222 } | 226 } |
223 | 227 |
224 if ok, err := c.HaveSpace("default", int64(len(validScript))); err != nil { | 228 if ok, err := c.HaveSpace("default", int64(len(validScript))); err != nil { |
225 t.Fatalf("HAVESPACE failed: %s", err) | 229 t.Fatalf("HAVESPACE failed: %s", err) |
226 } else if !ok { | 230 } else if !ok { |
227 t.Fatal("HaveSpace unexpectedly returned false") | 231 t.Fatal("HaveSpace unexpectedly returned false") |
228 } | 232 } |
229 | 233 |
230 if err = c.PutScript("default", validScript); err != nil { | 234 if warnings, err := c.PutScript("default", validScript); err != nil { |
231 t.Fatalf("PUTSCRIPT failed: %s", err) | 235 t.Fatalf("PUTSCRIPT failed: %s", err) |
236 } else if warnings != expectedWarnings { | |
237 t.Fatalf("PUTSCRIPT expected: %s, got %s", warnings, | |
238 expectedWarnings) | |
232 } | 239 } |
233 | 240 |
234 if err = c.ActivateScript("default"); err != nil { | 241 if err = c.ActivateScript("default"); err != nil { |
235 t.Fatalf("SETACTIVE failed: %s", err) | 242 t.Fatalf("SETACTIVE failed: %s", err) |
236 } | 243 } |
521 if err != nil { | 528 if err != nil { |
522 t.Fatalf("failed to create client: %s", err) | 529 t.Fatalf("failed to create client: %s", err) |
523 } | 530 } |
524 | 531 |
525 // invalid script name | 532 // invalid script name |
526 err = c.PutScript("def\u2028ault", validScript) | 533 _, err = c.PutScript("def\u2028ault", validScript) |
527 if err == nil { | 534 if err == nil { |
528 t.Fatalf("expected error but succeeded") | 535 t.Fatalf("expected error but succeeded") |
529 } | 536 } |
530 if _, ok := err.(managesieve.ProtocolError); !ok { | 537 if _, ok := err.(managesieve.ProtocolError); !ok { |
531 t.Fatalf("expected managesieve.ProtocolError, got %T (%q)", err, | 538 t.Fatalf("expected managesieve.ProtocolError, got %T (%q)", err, |
532 err) | 539 err) |
533 } | 540 } |
534 | 541 |
535 // EOF during upload | 542 // EOF during upload |
536 err = c.PutScript("default", validScript) | 543 _, err = c.PutScript("default", validScript) |
537 if err == nil { | 544 if err == nil { |
538 t.Fatalf("expected error but succeeded") | 545 t.Fatalf("expected error but succeeded") |
539 } | 546 } |
540 if _, ok := err.(*managesieve.ConnClosedError); !ok { | 547 if _, ok := err.(*managesieve.ConnClosedError); !ok { |
541 t.Fatalf("expected *managesieve.ConnClosedError, got %T (%q)", | 548 t.Fatalf("expected *managesieve.ConnClosedError, got %T (%q)", |
736 if _, ok := err.(managesieve.NotSupportedError); !ok { | 743 if _, ok := err.(managesieve.NotSupportedError); !ok { |
737 t.Fatalf("expected managesieve.NotSupportedError, got %T (%q)", | 744 t.Fatalf("expected managesieve.NotSupportedError, got %T (%q)", |
738 err, err) | 745 err, err) |
739 } | 746 } |
740 | 747 |
741 err = c.CheckScript(validScript) | 748 _, err = c.CheckScript(validScript) |
742 if err == nil { | 749 if err == nil { |
743 t.Fatalf("expected error but succeeded") | 750 t.Fatalf("expected error but succeeded") |
744 } | 751 } |
745 if _, ok := err.(managesieve.NotSupportedError); !ok { | 752 if _, ok := err.(managesieve.NotSupportedError); !ok { |
746 t.Fatalf("expected managesieve.NotSupportedError, got %T (%q)", | 753 t.Fatalf("expected managesieve.NotSupportedError, got %T (%q)", |