@@ -560,3 +560,42 @@ func TestValidCert(t *testing.T) {
560560 }
561561 }
562562}
563+
564+ type cacheGetFunc func (ctx context.Context , key string ) ([]byte , error )
565+
566+ func (f cacheGetFunc ) Get (ctx context.Context , key string ) ([]byte , error ) {
567+ return f (ctx , key )
568+ }
569+
570+ func (f cacheGetFunc ) Put (ctx context.Context , key string , data []byte ) error {
571+ return fmt .Errorf ("unsupported Put of %q = %q" , key , data )
572+ }
573+
574+ func (f cacheGetFunc ) Delete (ctx context.Context , key string ) error {
575+ return fmt .Errorf ("unsupported Delete of %q" , key )
576+ }
577+
578+ func TestManagerGetCertificateBogusSNI (t * testing.T ) {
579+ m := Manager {
580+ Prompt : AcceptTOS ,
581+ Cache : cacheGetFunc (func (ctx context.Context , key string ) ([]byte , error ) {
582+ return nil , fmt .Errorf ("cache.Get of %s" , key )
583+ }),
584+ }
585+ tests := []struct {
586+ name string
587+ wantErr string
588+ }{
589+ {"foo.com" , "cache.Get of foo.com" },
590+ {"foo.com." , "cache.Get of foo.com" },
591+ {`a\b` , "acme/autocert: bogus SNI value" },
592+ {"" , "acme/autocert: missing server name" },
593+ }
594+ for _ , tt := range tests {
595+ _ , err := m .GetCertificate (& tls.ClientHelloInfo {ServerName : tt .name })
596+ got := fmt .Sprint (err )
597+ if got != tt .wantErr {
598+ t .Errorf ("GetCertificate(SNI = %q) = %q; want %q" , tt .name , got , tt .wantErr )
599+ }
600+ }
601+ }
0 commit comments