Skip to content

Commit

Permalink
fixes to make tests pass under Go tip
Browse files Browse the repository at this point in the history
The old certificates in the tests are no longer considered valid and
fail with a "x509: RSA key missing NULL parameters" error
when parsing.
  • Loading branch information
rogpeppe committed Sep 28, 2016
1 parent 9e208be commit 23d54d3
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 200 deletions.
79 changes: 43 additions & 36 deletions cert/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func checkNotAfter(c *gc.C, cert *x509.Certificate, expiry time.Time) {
func (certSuite) TestParseCertificate(c *gc.C) {
xcert, err := cert.ParseCert(caCertPEM)
c.Assert(err, jc.ErrorIsNil)
c.Assert(xcert.Subject.CommonName, gc.Equals, "juju testing")
c.Assert(xcert.Subject.CommonName, gc.Equals, `juju-generated CA for model "juju testing"`)

xcert, err = cert.ParseCert(caKeyPEM)
c.Check(xcert, gc.IsNil)
Expand All @@ -61,7 +61,7 @@ func (certSuite) TestParseCertificate(c *gc.C) {
func (certSuite) TestParseCertAndKey(c *gc.C) {
xcert, key, err := cert.ParseCertAndKey(caCertPEM, caKeyPEM)
c.Assert(err, jc.ErrorIsNil)
c.Assert(xcert.Subject.CommonName, gc.Equals, "juju testing")
c.Assert(xcert.Subject.CommonName, gc.Equals, `juju-generated CA for model "juju testing"`)
c.Assert(key, gc.NotNil)

c.Assert(xcert.PublicKey.(*rsa.PublicKey), gc.DeepEquals, &key.PublicKey)
Expand Down Expand Up @@ -298,51 +298,58 @@ func roundTime(t time.Time) time.Time {
var (
caCertPEM = `
-----BEGIN CERTIFICATE-----
MIIBnTCCAUmgAwIBAgIBADALBgkqhkiG9w0BAQUwJjENMAsGA1UEChMEanVqdTEV
MBMGA1UEAxMManVqdSB0ZXN0aW5nMB4XDTEyMTExNDE0Mzg1NFoXDTIyMTExNDE0
NDM1NFowJjENMAsGA1UEChMEanVqdTEVMBMGA1UEAxMManVqdSB0ZXN0aW5nMFow
CwYJKoZIhvcNAQEBA0sAMEgCQQCC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
XUrBZO5UPZab66lJWXyseA==
-----END CERTIFICATE-----
`

caKeyPEM = `
-----BEGIN RSA PRIVATE KEY-----
MIIBOwIBAAJBAII46mf1pYpwqvYZAa3KDAPs91817Uj0FiI8CprYjfcXn7o+oV1+
6NQq+jJMkjpcbhCj8IQJpo32yaHKr0PHMyECAwEAAQJAYctedh4raLE+Ir0a3qnK
pjQSfiUggtYTvTf7+tfAnZu946PX88ysr7XHPkXEGP4tWDTbl8BfGndrTKswVOx6
RQIhAOT5OzafJneDQ5cuGLN/hxIPBLWxKT1/25O6dhtBlRyPAiEAkZfFvCtBZyKB
JFwDdp+7gE98mXtaFrjctLWeFx797U8CIAnnqiMTwWM8H2ljyhfBtYMXeTmu3zzU
0hfS4hcNwDiLAiEAkNXXU7YEPkFJD46ps1x7/s0UOutHV8tXZD44ou+l1GkCIQDO
HOzuvYngJpoClGw0ipzJPoNZ2Z/GkdOWGByPeKu/8g==
MIIBOgIBAAJBAL+0X+1zl2vt1wI41Q+RnlltJyaJmtwCbHRhREXVGU7t0kTMMNER
xqLnuNUyWRz90Rg8s9XvOtCqNYW7mypGrFECAwEAAQJAMPa+JaUHgO6foxam/LIB
0u95N3OgFR+dWeBaEsgKDclpREdJ0rXNI+3C3kwqeEZR4omoPlBeSEewSkwHxpmI
0QIhAOjKiHZ5v6R8haleipbDzkGUnZW07hEwL5Ld4MNx/QQ1AiEA0tEzSSNAdM0C
M/vY0x5mekIYai8/tFSEG9PJ3ZkpEy0CIQCo9B3YxwI1Un777vbs903iQQeiWP+U
EAHnOQvhLgDxpQIgGkpml+9igW5zoOH+h02aQBLwEoXz7tw/YW0HFrCcE70CIGkS
ve4WjiEqnQaHNAPy0hY/1DfIgBOSpOfnkFHOk9vX
-----END RSA PRIVATE KEY-----
`

nonCACert = `-----BEGIN CERTIFICATE-----
MIIBmjCCAUagAwIBAgIBADALBgkqhkiG9w0BAQUwJjENMAsGA1UEChMEanVqdTEV
MBMGA1UEAxMManVqdSB0ZXN0aW5nMB4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ATE KEY-----
`
)
2 changes: 1 addition & 1 deletion cmd/juju/application/upgradecharm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (s *UpgradeCharmErrorsStateSuite) TestSwitchAndPathFails(c *gc.C) {
func (s *UpgradeCharmErrorsStateSuite) TestInvalidRevision(c *gc.C) {
s.deployService(c)
err := runUpgradeCharm(c, "riak", "--revision=blah")
c.Assert(err, gc.ErrorMatches, `invalid value "blah" for flag --revision: strconv.ParseInt: parsing "blah": invalid syntax`)
c.Assert(err, gc.ErrorMatches, `invalid value "blah" for flag --revision: strconv.(ParseInt|Atoi): parsing "blah": invalid syntax`)
}

type BaseUpgradeCharmStateSuite struct{}
Expand Down
67 changes: 19 additions & 48 deletions environs/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"gopkg.in/juju/charmrepo.v2-unstable"
"gopkg.in/juju/environschema.v1"

"github.com/juju/juju/cert"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/juju/osenv"
"github.com/juju/juju/testing"
Expand Down Expand Up @@ -469,8 +470,8 @@ var configTests = []configTest{
"logforward-enabled": true,
"syslog-host": "localhost:1234",
"syslog-ca-cert": "abc",
"syslog-client-cert": caCert,
"syslog-client-key": caKey,
"syslog-client-cert": testing.CACert,
"syslog-client-key": testing.CAKey,
}),
err: `invalid syslog forwarding config: validating TLS config: parsing CA certificate: no certificates found`,
}, {
Expand All @@ -482,8 +483,8 @@ var configTests = []configTest{
"logforward-enabled": true,
"syslog-host": "localhost:1234",
"syslog-ca-cert": invalidCACert,
"syslog-client-cert": caCert,
"syslog-client-key": caKey,
"syslog-client-cert": testing.CACert,
"syslog-client-key": testing.CAKey,
}),
err: `invalid syslog forwarding config: validating TLS config: parsing CA certificate: asn1: syntax error: data truncated`,
}, {
Expand All @@ -492,9 +493,9 @@ var configTests = []configTest{
attrs: minimalConfigAttrs.Merge(testing.Attrs{
"logforward-enabled": true,
"syslog-host": "10.0.0.1:12345",
"syslog-ca-cert": caCert,
"syslog-ca-cert": testing.CACert,
"syslog-client-cert": invalidCACert,
"syslog-client-key": caKey,
"syslog-client-key": testing.CAKey,
}),
err: `invalid syslog forwarding config: validating TLS config: parsing client key pair: asn1: syntax error: data truncated`,
}, {
Expand All @@ -503,8 +504,8 @@ var configTests = []configTest{
attrs: minimalConfigAttrs.Merge(testing.Attrs{
"logforward-enabled": true,
"syslog-host": "10.0.0.1:12345",
"syslog-ca-cert": caCert,
"syslog-client-cert": caCert,
"syslog-ca-cert": testing.CACert,
"syslog-client-cert": testing.CACert,
"syslog-client-key": invalidCAKey,
}),
err: `invalid syslog forwarding config: validating TLS config: parsing client key pair: (crypto/)?tls: failed to parse private key`,
Expand All @@ -514,9 +515,9 @@ var configTests = []configTest{
attrs: minimalConfigAttrs.Merge(testing.Attrs{
"logforward-enabled": true,
"syslog-host": "10.0.0.1:12345",
"syslog-ca-cert": caCert,
"syslog-client-cert": caCert,
"syslog-client-key": caKey2,
"syslog-ca-cert": testing.CACert,
"syslog-client-cert": testing.ServerCert,
"syslog-client-key": serverKey2,
}),
err: `invalid syslog forwarding config: validating TLS config: parsing client key pair: (crypto/)?tls: private key does not match public key`,
}, {
Expand Down Expand Up @@ -1183,43 +1184,13 @@ func (s *specializedCharmRepo) WithTestMode() charmrepo.Interface {
return s
}

var caCert = `
-----BEGIN CERTIFICATE-----
MIIBjDCCATigAwIBAgIBADALBgkqhkiG9w0BAQUwHjENMAsGA1UEChMEanVqdTEN
MAsGA1UEAxMEcm9vdDAeFw0xMjExMDkxNjQwMjhaFw0yMjExMDkxNjQ1MjhaMB4x
DTALBgNVBAoTBGp1anUxDTALBgNVBAMTBHJvb3QwWTALBgkqhkiG9w0BAQEDSgAw
RwJAduA1Gnb2VJLxNGfG4St0Qy48Y3q5Z5HheGtTGmti/FjlvQvScCFGCnJG7fKA
Knd7ia3vWg7lxYkIvMPVP88LAQIDAQABo2YwZDAOBgNVHQ8BAf8EBAMCAKQwEgYD
VR0TAQH/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JCtmxA
jQMuvZWRe6khAiBvMztYtPSDKXRbCZ4xeQ+kWSDHtok8Y5zNoTeu4nvDrwIgb3Al
fikzPveC5g6S6OvEQmyDz59tYBubm2XHgvxqww0=
-----END RSA PRIVATE KEY-----
`[1:]
var serverKey2 = func() string {
_, key, err := cert.NewDefaultServer(testing.CACert, testing.CAKey, nil)
if err != nil {
panic(err)
}
return string(key)
}()

var invalidCAKey = `
-----BEGIN RSA PRIVATE KEY-----
Expand Down
2 changes: 1 addition & 1 deletion logfwd/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (s *LocationSuite) TestParseLocationMissingLine(c *gc.C) {
func (s *LocationSuite) TestParseLocationBogusLine(c *gc.C) {
_, err := logfwd.ParseLocation(validLocation.Module, "spam.go:xxx")

c.Check(err, gc.ErrorMatches, `failed to parse sourceLine: line number must be non-negative integer: strconv.ParseInt: parsing "xxx": invalid syntax`)
c.Check(err, gc.ErrorMatches, `failed to parse sourceLine: line number must be non-negative integer: strconv.(ParseInt|Atoi): parsing "xxx": invalid syntax`)
}

func (s *LocationSuite) TestValidateValid(c *gc.C) {
Expand Down
Loading

0 comments on commit 23d54d3

Please sign in to comment.