(t *testing.T)
| 147 | } |
| 148 | |
| 149 | func TestHandlePeerAPI(t *testing.T) { |
| 150 | tests := []struct { |
| 151 | name string |
| 152 | isSelf bool // the peer sending the request is owned by us |
| 153 | capSharing bool // self node has file sharing capability |
| 154 | debugCap bool // self node has debug capability |
| 155 | omitRoot bool // don't configure |
| 156 | reqs []*http.Request |
| 157 | checks []check |
| 158 | }{ |
| 159 | { |
| 160 | name: "reject_non_owner_put", |
| 161 | isSelf: false, |
| 162 | capSharing: true, |
| 163 | reqs: []*http.Request{httptest.NewRequest("PUT", "/v0/put/foo", nil)}, |
| 164 | checks: checks( |
| 165 | httpStatus(http.StatusForbidden), |
| 166 | bodyContains("Taildrop disabled"), |
| 167 | ), |
| 168 | }, |
| 169 | { |
| 170 | name: "owner_without_cap", |
| 171 | isSelf: true, |
| 172 | capSharing: false, |
| 173 | reqs: []*http.Request{httptest.NewRequest("PUT", "/v0/put/foo", nil)}, |
| 174 | checks: checks( |
| 175 | httpStatus(http.StatusForbidden), |
| 176 | bodyContains("Taildrop disabled"), |
| 177 | ), |
| 178 | }, |
| 179 | { |
| 180 | name: "owner_with_cap_no_rootdir", |
| 181 | omitRoot: true, |
| 182 | isSelf: true, |
| 183 | capSharing: true, |
| 184 | reqs: []*http.Request{httptest.NewRequest("PUT", "/v0/put/foo", nil)}, |
| 185 | checks: checks( |
| 186 | httpStatus(http.StatusForbidden), |
| 187 | bodyContains("Taildrop disabled"), |
| 188 | ), |
| 189 | }, |
| 190 | |
| 191 | { |
| 192 | name: "bad_method", |
| 193 | isSelf: true, |
| 194 | capSharing: true, |
| 195 | reqs: []*http.Request{httptest.NewRequest("POST", "/v0/put/foo", nil)}, |
| 196 | checks: checks( |
| 197 | httpStatus(405), |
| 198 | bodyContains("expected method GET or PUT"), |
| 199 | ), |
| 200 | }, |
| 201 | { |
| 202 | name: "put_zero_length", |
| 203 | isSelf: true, |
| 204 | capSharing: true, |
| 205 | reqs: []*http.Request{httptest.NewRequest("PUT", "/v0/put/foo", nil)}, |
| 206 | checks: checks( |
nothing calls this directly
no test coverage detected
searching dependent graphs…