Imported Upstream version 4.7.3
[platform/upstream/gcc48.git] / libgo / go / crypto / tls / root_test.go
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package tls
6
7 import (
8         "crypto/x509"
9         "runtime"
10         "testing"
11 )
12
13 var tlsServers = []string{
14         "google.com",
15         "github.com",
16         "twitter.com",
17 }
18
19 func TestOSCertBundles(t *testing.T) {
20         if testing.Short() {
21                 t.Logf("skipping certificate tests in short mode")
22                 return
23         }
24
25         for _, addr := range tlsServers {
26                 conn, err := Dial("tcp", addr+":443", &Config{ServerName: addr})
27                 if err != nil {
28                         t.Errorf("unable to verify %v: %v", addr, err)
29                         continue
30                 }
31                 err = conn.Close()
32                 if err != nil {
33                         t.Error(err)
34                 }
35         }
36 }
37
38 func TestCertHostnameVerifyWindows(t *testing.T) {
39         if runtime.GOOS != "windows" {
40                 return
41         }
42
43         if testing.Short() {
44                 t.Logf("skipping certificate tests in short mode")
45                 return
46         }
47
48         for _, addr := range tlsServers {
49                 cfg := &Config{ServerName: "example.com"}
50                 conn, err := Dial("tcp", addr+":443", cfg)
51                 if err == nil {
52                         conn.Close()
53                         t.Errorf("should fail to verify for example.com: %v", addr)
54                         continue
55                 }
56                 _, ok := err.(x509.HostnameError)
57                 if !ok {
58                         t.Errorf("error type mismatch, got: %v", err)
59                 }
60         }
61 }