(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestValidateWebpushEndpoint(t *testing.T) { |
| 11 | t.Parallel() |
| 12 | |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | endpoint string |
| 16 | wantErr bool |
| 17 | errSubstr string |
| 18 | }{ |
| 19 | { |
| 20 | name: "valid https endpoint", |
| 21 | endpoint: "https://fcm.googleapis.com/fcm/send/abc123", |
| 22 | wantErr: false, |
| 23 | }, |
| 24 | { |
| 25 | name: "valid https endpoint with port", |
| 26 | endpoint: "https://push.example.com:8443/subscription", |
| 27 | wantErr: false, |
| 28 | }, |
| 29 | { |
| 30 | name: "relative URL", |
| 31 | endpoint: "/push/subscription", |
| 32 | wantErr: true, |
| 33 | errSubstr: "absolute URL", |
| 34 | }, |
| 35 | { |
| 36 | name: "http scheme rejected", |
| 37 | endpoint: "http://push.example.com/subscription", |
| 38 | wantErr: true, |
| 39 | errSubstr: "scheme must be https", |
| 40 | }, |
| 41 | { |
| 42 | name: "custom scheme rejected", |
| 43 | endpoint: "ws://push.example.com/subscription", |
| 44 | wantErr: true, |
| 45 | errSubstr: "scheme must be https", |
| 46 | }, |
| 47 | { |
| 48 | name: "empty host", |
| 49 | endpoint: "https:///path", |
| 50 | wantErr: true, |
| 51 | errSubstr: "host is required", |
| 52 | }, |
| 53 | { |
| 54 | name: "userinfo rejected", |
| 55 | endpoint: "https://user:pass@push.example.com/subscription", |
| 56 | wantErr: true, |
| 57 | errSubstr: "must not include userinfo", |
| 58 | }, |
| 59 | { |
| 60 | name: "localhost rejected", |
| 61 | endpoint: "https://localhost/subscription", |
| 62 | wantErr: true, |
| 63 | errSubstr: "must not be localhost", |
| 64 | }, |
| 65 | { |
| 66 | name: "subdomain of localhost rejected", |
| 67 | endpoint: "https://foo.localhost/subscription", |
nothing calls this directly
no test coverage detected