...

Source file src/github.com/googleapis/enterprise-certificate-proxy/internal/signer/util/util_test.go

Documentation: github.com/googleapis/enterprise-certificate-proxy/internal/signer/util

     1  // Copyright 2022 Google LLC.
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  //     https://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package util
    15  
    16  import (
    17  	"testing"
    18  )
    19  
    20  func TestLoadConfig(t *testing.T) {
    21  	config, err := LoadConfig("./test_data/certificate_config.json")
    22  	// darwin
    23  	if err != nil {
    24  		t.Fatalf("LoadConfig error: %q", err)
    25  	}
    26  	want := "Google Endpoint Verification"
    27  	if config.CertConfigs.MacOSKeychain.Issuer != want {
    28  		t.Errorf("Expected issuer is %q, got: %q", want, config.CertConfigs.MacOSKeychain.Issuer)
    29  	}
    30  
    31  	// windows
    32  	want = "enterprise_v1_corp_client"
    33  	if config.CertConfigs.WindowsStore.Issuer != want {
    34  		t.Errorf("Expected issuer is %q, got: %q", want, config.CertConfigs.WindowsStore.Issuer)
    35  	}
    36  	want = "MY"
    37  	if config.CertConfigs.WindowsStore.Store != want {
    38  		t.Errorf("Expected store is %q, got: %q", want, config.CertConfigs.WindowsStore.Store)
    39  	}
    40  	want = "current_user"
    41  	if config.CertConfigs.WindowsStore.Provider != want {
    42  		t.Errorf("Expected provider is %q, got: %q", want, config.CertConfigs.WindowsStore.Provider)
    43  	}
    44  
    45  	// pkcs11
    46  	want = "0x1739427"
    47  	if config.CertConfigs.PKCS11.Slot != want {
    48  		t.Errorf("Expected slot is %v, got: %v", want, config.CertConfigs.PKCS11.Slot)
    49  	}
    50  	want = "gecc"
    51  	if config.CertConfigs.PKCS11.Label != want {
    52  		t.Errorf("Expected label is %v, got: %v", want, config.CertConfigs.PKCS11.Label)
    53  	}
    54  	want = "pkcs11_module.so"
    55  	if config.CertConfigs.PKCS11.PKCS11Module != want {
    56  		t.Errorf("Expected pkcs11_module is %v, got: %v", want, config.CertConfigs.PKCS11.PKCS11Module)
    57  	}
    58  	want = "0000"
    59  	if config.CertConfigs.PKCS11.UserPin != want {
    60  		t.Errorf("Expected user pin is %v, got: %v", want, config.CertConfigs.PKCS11.UserPin)
    61  	}
    62  }
    63  
    64  func TestLoadConfigMissing(t *testing.T) {
    65  	_, err := LoadConfig("./test_data/certificate_config_missing.json")
    66  	if err == nil {
    67  		t.Error("Expected error but got nil")
    68  	}
    69  }
    70  

View as plain text