(t *testing.T)
| 146 | } |
| 147 | |
| 148 | func TestWebpushSubscribeRejectsInvalidEndpoint(t *testing.T) { |
| 149 | t.Parallel() |
| 150 | |
| 151 | ctx := testutil.Context(t, testutil.WaitShort) |
| 152 | client := coderdtest.New(t, &coderdtest.Options{ |
| 153 | WebpushDispatcher: &testWebpushDispatcher{}, |
| 154 | }) |
| 155 | owner := coderdtest.CreateFirstUser(t, client) |
| 156 | memberClient, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID) |
| 157 | |
| 158 | err := memberClient.PostWebpushSubscription(ctx, "me", codersdk.WebpushSubscription{ |
| 159 | Endpoint: "http://127.0.0.1:8080/subscription", |
| 160 | AuthKey: validEndpointAuthKey, |
| 161 | P256DHKey: validEndpointP256dhKey, |
| 162 | }) |
| 163 | var sdkError *codersdk.Error |
| 164 | require.Error(t, err) |
| 165 | require.ErrorAsf(t, err, &sdkError, "error should be of type *codersdk.Error") |
| 166 | require.Equal(t, http.StatusBadRequest, sdkError.StatusCode()) |
| 167 | require.Contains(t, sdkError.Error(), "endpoint URL scheme must be https") |
| 168 | } |
| 169 | |
| 170 | // testWebpushErrorStore wraps a real database.Store and allows injecting |
| 171 | // errors into GetWebpushSubscriptionsByUserID. |
nothing calls this directly
no test coverage detected