(t *testing.T)
| 88 | } |
| 89 | |
| 90 | func TestIsAllowedCertificateURL(t *testing.T) { |
| 91 | t.Parallel() |
| 92 | tests := []struct { |
| 93 | name string |
| 94 | url string |
| 95 | allowed bool |
| 96 | }{ |
| 97 | {"microsoft http", "http://www.microsoft.com/pki/mscorp/cert.crt", true}, |
| 98 | {"microsoft https", "https://www.microsoft.com/pkiops/certs/cert.crt", true}, |
| 99 | {"digicert http", "http://cacerts.digicert.com/DigiCertGlobalRootG2.crt", true}, |
| 100 | {"digicert https", "https://cacerts.digicert.com/DigiCertGlobalRootG3.crt", true}, |
| 101 | {"evil domain", "http://evil.example.com/cert.crt", false}, |
| 102 | {"metadata endpoint", "http://169.254.169.254/latest/meta-data/", false}, |
| 103 | {"localhost", "http://localhost/secret", false}, |
| 104 | {"subdomain trick", "http://www.microsoft.com.evil.com/cert.crt", false}, |
| 105 | {"empty string", "", false}, |
| 106 | {"ftp scheme", "ftp://www.microsoft.com/cert.crt", false}, |
| 107 | {"no scheme", "www.microsoft.com/cert.crt", false}, |
| 108 | {"javascript scheme", "javascript:alert(1)", false}, |
| 109 | {"microsoft with path", "http://www.microsoft.com/pkiops/certs/cert.crt", true}, |
| 110 | {"microsoft explicit port 80", "http://www.microsoft.com:80/cert.crt", true}, |
| 111 | {"microsoft explicit port 443", "https://www.microsoft.com:443/cert.crt", true}, |
| 112 | {"microsoft non-standard port", "http://www.microsoft.com:8080/cert.crt", false}, |
| 113 | {"microsoft port 22", "http://www.microsoft.com:22/cert.crt", false}, |
| 114 | } |
| 115 | for _, tc := range tests { |
| 116 | t.Run(tc.name, func(t *testing.T) { |
| 117 | t.Parallel() |
| 118 | result := azureidentity.IsAllowedCertificateURL(tc.url) |
| 119 | require.Equal(t, tc.allowed, result, "URL: %s", tc.url) |
| 120 | }) |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // testCertChain holds a three-level certificate hierarchy (Root CA, |
| 125 | // Intermediate CA, Signing/leaf) together with their private keys. |
nothing calls this directly
no test coverage detected