comparison managesieve_test.go @ 12:66b46b3d73be default tip

Handle capabilities sent by the server after negotiating a SASL security layer
author Guido Berhoerster <guido+managesieve@berhoerster.name>
date Tue, 09 Feb 2021 23:01:02 +0100
parents b790df0733d4
children
comparison
equal deleted inserted replaced
11:b790df0733d4 12:66b46b3d73be
789 if _, ok := err.(*managesieve.HostNameVerificationError); !ok { 789 if _, ok := err.(*managesieve.HostNameVerificationError); !ok {
790 t.Fatalf("expected *managesieve.HostNameVerificationError, got %T (%q)", err, err) 790 t.Fatalf("expected *managesieve.HostNameVerificationError, got %T (%q)", err, err)
791 } 791 }
792 } 792 }
793 793
794 // capabilities sent by the server after negotiating a secure SASL-layer
795 var authCapabilitiesResponse string = `"IMPLEMENTATION" "Example"
796 "SASL" "PLAIN TEST"
797 "SIEVE" "fileinto vacation"
798 "StARTTLS"
799 "VERSION" "1.0"
800 OK
801 "cXV1eCxnYXJwbHk="
802 "d2FsZG8sZnJlZA=="
803 OK (SASL "eHl6enkgdGh1ZA==")
804 "IMPLEMENTATION" "Example"
805 "SASL" "PLAIN TEST"
806 "SIEVE" "fileinto vacation"
807 "StARTTLS"
808 "VERSION" "1.0"
809 OK
810 "default"
811 OK
812 `
813
814 func TestAuthCapabilitiesResponse(t *testing.T) {
815 conn := newFakeConn(authCapabilitiesResponse)
816 c, err := managesieve.NewClient(conn, "localhost")
817 if err != nil {
818 t.Fatalf("failed to create client: %s", err)
819 }
820
821 auth := &testAuth{}
822 if err = c.Authenticate(auth); err != nil {
823 t.Fatalf("failed to authenticate: %s", err)
824 }
825
826 if scripts, _, err := c.ListScripts(); err != nil {
827 t.Fatalf("failed to list scripts after authentication: %s", err)
828 } else if len(scripts) != 1 {
829 t.Fatalf("expected list of scripts but got none")
830 }
831 }
832
794 // authentication failure due to invalid credentials 833 // authentication failure due to invalid credentials
795 func TestPlainAuthDenied(t *testing.T) { 834 func TestPlainAuthDenied(t *testing.T) {
796 conn := newFakeConn(minimalServer + 835 conn := newFakeConn(minimalServer +
797 "NO \"invalid username or password\"\n") 836 "NO \"invalid username or password\"\n")
798 c, err := managesieve.NewClient(conn, "localhost") 837 c, err := managesieve.NewClient(conn, "localhost")
884 resp = []byte(fmt.Sprintf("qux=%d", a.i)) 923 resp = []byte(fmt.Sprintf("qux=%d", a.i))
885 } 924 }
886 return resp, nil 925 return resp, nil
887 } 926 }
888 927
928 func (a *testAuth) SASLSecurityLayer() bool {
929 return true
930 }
931
889 // authentication using a custom authentication method 932 // authentication using a custom authentication method
890 func TestCustomAuth(t *testing.T) { 933 func TestCustomAuth(t *testing.T) {
891 conn := newFakeConn(customAuthServer) 934 conn := newFakeConn(customAuthServer)
892 c, err := managesieve.NewClient(conn, "localhost") 935 c, err := managesieve.NewClient(conn, "localhost")
893 if err != nil { 936 if err != nil {
973 t.Fatalf("expected error but succeeded") 1016 t.Fatalf("expected error but succeeded")
974 } 1017 }
975 if _, ok := err.(managesieve.ParserError); !ok { 1018 if _, ok := err.(managesieve.ParserError); !ok {
976 t.Fatalf("expected managesieve.ParserError, got %T (%q)", err, err) 1019 t.Fatalf("expected managesieve.ParserError, got %T (%q)", err, err)
977 } 1020 }
1021
978 } 1022 }
979 1023
980 // response to aborted SASL authentication is not NO 1024 // response to aborted SASL authentication is not NO
981 var invalidAuthAbortServer string = `"IMPLEMENTATION" "Example" 1025 var invalidAuthAbortServer string = `"IMPLEMENTATION" "Example"
982 "SASL" "PLAIN TEST" 1026 "SASL" "PLAIN TEST"