(t *testing.T)
| 106 | } |
| 107 | |
| 108 | func TestBasic_Authorised(t *testing.T) { |
| 109 | basicAuth, err := createBasicAuth("foo", "bar", t) |
| 110 | creds := []byte("foo:bar") |
| 111 | |
| 112 | if err != nil { |
| 113 | t.Fatal(err) |
| 114 | } |
| 115 | |
| 116 | tests := []struct { |
| 117 | name string |
| 118 | req *http.Request |
| 119 | res http.ResponseWriter |
| 120 | out bool |
| 121 | }{ |
| 122 | { |
| 123 | "correct credentials should be authorized", |
| 124 | &http.Request{ |
| 125 | Header: http.Header{ |
| 126 | "Authorization": []string{fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString(creds))}, |
| 127 | }, |
| 128 | }, |
| 129 | &responseWriter{}, |
| 130 | true, |
| 131 | }, |
| 132 | { |
| 133 | "incorrect credentials should not be authorized", |
| 134 | &http.Request{ |
| 135 | Header: http.Header{ |
| 136 | "Authorization": []string{fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte("baz:blarg")))}, |
| 137 | }, |
| 138 | }, |
| 139 | &responseWriter{}, |
| 140 | false, |
| 141 | }, |
| 142 | { |
| 143 | "missing Authorization header should not be authorized", |
| 144 | &http.Request{ |
| 145 | Header: http.Header{}, |
| 146 | }, |
| 147 | &responseWriter{}, |
| 148 | false, |
| 149 | }, |
| 150 | { |
| 151 | "malformed Authorization header should not be authorized", |
| 152 | &http.Request{ |
| 153 | Header: http.Header{ |
| 154 | "Authorization": []string{"malformed"}, |
| 155 | }, |
| 156 | }, |
| 157 | &responseWriter{}, |
| 158 | false, |
| 159 | }, |
| 160 | } |
| 161 | |
| 162 | for _, tt := range tests { |
| 163 | t.Run(tt.name, func(t *testing.T) { |
| 164 | if got, want := basicAuth.Authorized(tt.req, tt.res), tt.out; !reflect.DeepEqual(got, want) { |
| 165 | t.Errorf("got %v want %v", got, want) |
nothing calls this directly
no test coverage detected