...

Source file src/github.com/sigstore/rekor/pkg/signer/file_test.go

Documentation: github.com/sigstore/rekor/pkg/signer

     1  /*
     2  Copyright The Rekor Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package signer
    18  
    19  import (
    20  	"os"
    21  	"path/filepath"
    22  	"testing"
    23  )
    24  
    25  const testEcdsaKey = `
    26  -----BEGIN EC PRIVATE KEY-----
    27  Proc-Type: 4,ENCRYPTED
    28  DEK-Info: AES-256-CBC,1ee56fe067d83265fe430391edfa6586
    29  
    30  W5NqqRe5rOVe4OvxehYKm6wscR1JFoyRyd8M+Rutp8Q2lxPuKFhR4FZ61b0yy6pr
    31  LGJGQWOTIZxrNZ8g4JeS9I3huDWGloZRI2fbTg69HK4EiQQWUc1wS1TWAVoaf4fr
    32  LclBWxp2UzqHDaNJ0/2DoGFZhaeMU84VA1O41lO+p5Cx4bms0yWeEHwOrf2AmnNY
    33  l5Zm9zoPpXxaDEPSTs5c1loRmmxPHKgb68oZPxEnsCg=
    34  -----END EC PRIVATE KEY-----`
    35  
    36  func TestFile(t *testing.T) {
    37  	testKeyPass := `password123`
    38  	td := t.TempDir()
    39  	keyFile := filepath.Join(td, "ecdsa-key.pem")
    40  	if err := os.WriteFile(keyFile, []byte(testEcdsaKey), 0644); err != nil {
    41  		t.Fatal(err)
    42  	}
    43  
    44  	tests := []struct {
    45  		name    string
    46  		keyPath string
    47  		keyPass string
    48  		wantErr bool
    49  	}{
    50  		{
    51  			name:    "valid ecdsa",
    52  			keyPath: keyFile,
    53  			keyPass: testKeyPass,
    54  			wantErr: false,
    55  		},
    56  		{
    57  			name:    "invalid pass",
    58  			keyPath: keyFile,
    59  			keyPass: "123",
    60  			wantErr: true,
    61  		},
    62  	}
    63  	for _, tc := range tests {
    64  		t.Run(tc.name, func(t *testing.T) {
    65  			tc := tc
    66  			_, err := NewFile(tc.keyPath, tc.keyPass)
    67  			if tc.wantErr != (err != nil) {
    68  				t.Errorf("NewFile() expected %t, got err %s", tc.wantErr, err)
    69  			}
    70  		})
    71  	}
    72  }
    73  

View as plain text