(t *testing.T)
| 1645 | } |
| 1646 | |
| 1647 | func TestRequestSignature(t *testing.T) { |
| 1648 | testCases := map[string]struct { |
| 1649 | method string |
| 1650 | body string |
| 1651 | key string |
| 1652 | resp string |
| 1653 | }{ |
| 1654 | "No request signature": { |
| 1655 | method: http.MethodGet, |
| 1656 | body: "", |
| 1657 | key: "", |
| 1658 | resp: "no signature received", |
| 1659 | }, |
| 1660 | "Get request": { |
| 1661 | method: http.MethodGet, |
| 1662 | body: "", |
| 1663 | key: "7d9e1aa87a5954e6f9fc59266b3af9d7c35fda2d", |
| 1664 | resp: "signatures match", |
| 1665 | }, |
| 1666 | "Post request": { |
| 1667 | method: http.MethodPost, |
| 1668 | body: `{ "hello": "world!" }`, |
| 1669 | key: "d90df39e2d19282840252612dd7c81421a372f61", |
| 1670 | resp: "signatures match", |
| 1671 | }, |
| 1672 | } |
| 1673 | for name, tc := range testCases { |
| 1674 | t.Run(name, func(t *testing.T) { |
| 1675 | st, err := NewSignatureTest() |
| 1676 | if err != nil { |
| 1677 | t.Fatal(err) |
| 1678 | } |
| 1679 | t.Cleanup(st.Close) |
| 1680 | if tc.key != "" { |
| 1681 | st.opts.SignatureKey = fmt.Sprintf("sha1:%s", tc.key) |
| 1682 | } |
| 1683 | err = st.MakeRequestWithExpectedKey(tc.method, tc.body, tc.key) |
| 1684 | assert.NoError(t, err) |
| 1685 | assert.Equal(t, 200, st.rw.Code) |
| 1686 | assert.Equal(t, tc.resp, st.rw.Body.String()) |
| 1687 | }) |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | type ajaxRequestTest struct { |
| 1692 | opts *options.Options |
nothing calls this directly
no test coverage detected