...

Source file src/github.com/letsencrypt/boulder/ca/ecdsa_allow_list_test.go

Documentation: github.com/letsencrypt/boulder/ca

     1  package ca
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestNewECDSAAllowListFromFile(t *testing.T) {
     8  	type args struct {
     9  		filename string
    10  	}
    11  	tests := []struct {
    12  		name              string
    13  		args              args
    14  		want1337Permitted bool
    15  		wantEntries       int
    16  		wantErrBool       bool
    17  	}{
    18  		{
    19  			name:              "one entry",
    20  			args:              args{"testdata/ecdsa_allow_list.yml"},
    21  			want1337Permitted: true,
    22  			wantEntries:       1,
    23  			wantErrBool:       false,
    24  		},
    25  		{
    26  			name:              "one entry but it's not 1337",
    27  			args:              args{"testdata/ecdsa_allow_list2.yml"},
    28  			want1337Permitted: false,
    29  			wantEntries:       1,
    30  			wantErrBool:       false,
    31  		},
    32  		{
    33  			name:              "should error due to no file",
    34  			args:              args{"testdata/ecdsa_allow_list_no_exist.yml"},
    35  			want1337Permitted: false,
    36  			wantEntries:       0,
    37  			wantErrBool:       true,
    38  		},
    39  		{
    40  			name:              "should error due to malformed YAML",
    41  			args:              args{"testdata/ecdsa_allow_list_malformed.yml"},
    42  			want1337Permitted: false,
    43  			wantEntries:       0,
    44  			wantErrBool:       true,
    45  		},
    46  	}
    47  
    48  	for _, tt := range tests {
    49  		t.Run(tt.name, func(t *testing.T) {
    50  			allowList, gotEntries, err := NewECDSAAllowListFromFile(tt.args.filename)
    51  
    52  			if (err != nil) != tt.wantErrBool {
    53  				t.Errorf("NewECDSAAllowListFromFile() error = %v, wantErr %v", err, tt.wantErrBool)
    54  				t.Error(allowList, gotEntries, err)
    55  				return
    56  			}
    57  			if allowList != nil && allowList.permitted(1337) != tt.want1337Permitted {
    58  				t.Errorf("NewECDSAAllowListFromFile() allowList = %v, want %v", allowList, tt.want1337Permitted)
    59  			}
    60  			if gotEntries != tt.wantEntries {
    61  				t.Errorf("NewECDSAAllowListFromFile() gotEntries = %v, want %v", gotEntries, tt.wantEntries)
    62  			}
    63  		})
    64  	}
    65  }
    66  

View as plain text