(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestValidateConfig(t *testing.T) { |
| 19 | cert, err := selfsign.GenerateSelfSigned() |
| 20 | if err != nil { |
| 21 | assert.NoError(t, err, "TestValidateConfig: Config validation error, self signed certificate not generated") |
| 22 | |
| 23 | return |
| 24 | } |
| 25 | dsaPrivateKey := &dsa.PrivateKey{} |
| 26 | err = dsa.GenerateParameters(&dsaPrivateKey.Parameters, rand.Reader, dsa.L1024N160) |
| 27 | if err != nil { |
| 28 | assert.NoError(t, err, "TestValidateConfig: Config validation error, DSA parameters not generated") |
| 29 | |
| 30 | return |
| 31 | } |
| 32 | err = dsa.GenerateKey(dsaPrivateKey, rand.Reader) |
| 33 | if err != nil { |
| 34 | assert.NoError(t, err, "TestValidateConfig: Config validation error, DSA private key not generated") |
| 35 | |
| 36 | return |
| 37 | } |
| 38 | rsaPrivateKey, err := rsa.GenerateKey(rand.Reader, 2048) |
| 39 | if err != nil { |
| 40 | assert.NoError(t, err, "TestValidateConfig: Config validation error, RSA private key not generated") |
| 41 | |
| 42 | return |
| 43 | } |
| 44 | cases := map[string]struct { |
| 45 | config *Config |
| 46 | wantAnyErr bool |
| 47 | expErr error |
| 48 | }{ |
| 49 | "Empty config": { |
| 50 | expErr: errNoConfigProvided, |
| 51 | }, |
| 52 | "PSK and Certificate, valid cipher suites": { |
| 53 | config: &Config{ |
| 54 | CipherSuites: []CipherSuiteID{TLS_PSK_WITH_AES_128_CCM_8, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 55 | PSK: func([]byte) ([]byte, error) { |
| 56 | return nil, nil |
| 57 | }, |
| 58 | Certificates: []tls.Certificate{cert}, |
| 59 | }, |
| 60 | }, |
| 61 | "PSK and Certificate, no PSK cipher suite": { |
| 62 | config: &Config{ |
| 63 | CipherSuites: []CipherSuiteID{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}, |
| 64 | PSK: func([]byte) ([]byte, error) { |
| 65 | return nil, nil |
| 66 | }, |
| 67 | Certificates: []tls.Certificate{cert}, |
| 68 | }, |
| 69 | expErr: errNoAvailablePSKCipherSuite, |
| 70 | }, |
| 71 | "PSK and Certificate, no non-PSK cipher suite": { |
| 72 | config: &Config{ |
| 73 | CipherSuites: []CipherSuiteID{TLS_PSK_WITH_AES_128_CCM_8}, |
| 74 | PSK: func([]byte) ([]byte, error) { |
| 75 | return nil, nil |
nothing calls this directly
no test coverage detected
searching dependent graphs…