...

Source file src/github.com/letsencrypt/boulder/iana/iana_test.go

Documentation: github.com/letsencrypt/boulder/iana

     1  package iana
     2  
     3  import "testing"
     4  
     5  func TestExtractSuffix_Valid(t *testing.T) {
     6  	testCases := []struct {
     7  		domain, want string
     8  	}{
     9  		// TLD with only 1 rule.
    10  		{"biz", "biz"},
    11  		{"domain.biz", "biz"},
    12  		{"b.domain.biz", "biz"},
    13  
    14  		// The relevant {kobe,kyoto}.jp rules are:
    15  		// jp
    16  		// *.kobe.jp
    17  		// !city.kobe.jp
    18  		// kyoto.jp
    19  		// ide.kyoto.jp
    20  		{"jp", "jp"},
    21  		{"kobe.jp", "jp"},
    22  		{"c.kobe.jp", "c.kobe.jp"},
    23  		{"b.c.kobe.jp", "c.kobe.jp"},
    24  		{"a.b.c.kobe.jp", "c.kobe.jp"},
    25  		{"city.kobe.jp", "kobe.jp"},
    26  		{"www.city.kobe.jp", "kobe.jp"},
    27  		{"kyoto.jp", "kyoto.jp"},
    28  		{"test.kyoto.jp", "kyoto.jp"},
    29  		{"ide.kyoto.jp", "ide.kyoto.jp"},
    30  		{"b.ide.kyoto.jp", "ide.kyoto.jp"},
    31  		{"a.b.ide.kyoto.jp", "ide.kyoto.jp"},
    32  
    33  		// Domain with a private public suffix should return the ICANN public suffix.
    34  		{"foo.compute-1.amazonaws.com", "com"},
    35  		// Domain equal to a private public suffix should return the ICANN public
    36  		// suffix.
    37  		{"cloudapp.net", "net"},
    38  	}
    39  
    40  	for _, tc := range testCases {
    41  		got, err := ExtractSuffix(tc.domain)
    42  		if err != nil {
    43  			t.Errorf("%q: returned error", tc.domain)
    44  			continue
    45  		}
    46  		if got != tc.want {
    47  			t.Errorf("%q: got %q, want %q", tc.domain, got, tc.want)
    48  		}
    49  	}
    50  }
    51  
    52  func TestExtractSuffix_Invalid(t *testing.T) {
    53  	testCases := []string{
    54  		"",
    55  		"example",
    56  		"example.example",
    57  	}
    58  
    59  	for _, tc := range testCases {
    60  		_, err := ExtractSuffix(tc)
    61  		if err == nil {
    62  			t.Errorf("%q: expected err, got none", tc)
    63  		}
    64  	}
    65  }
    66  

View as plain text