github.com/blend/go-sdk@v1.20220411.3/vault/transit_opts_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package vault
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  func TestTransitCreateOptConfig(t *testing.T) {
    17  	a := assert.New(t)
    18  	cfg := CreateTransitKeyConfig{
    19  		Derived:    true,
    20  		Convergent: true,
    21  	}
    22  
    23  	empty := &CreateTransitKeyConfig{}
    24  
    25  	a.Nil(OptCreateTransitConfig(cfg)(empty))
    26  
    27  	a.True(empty.Derived)
    28  	a.True(empty.Convergent)
    29  }
    30  
    31  func TestTransitUpdateOptConfig(t *testing.T) {
    32  	a := assert.New(t)
    33  	cfg := UpdateTransitKeyConfig{
    34  		Exportable:           true,
    35  		AllowPlaintextBackup: true,
    36  	}
    37  
    38  	empty := &UpdateTransitKeyConfig{}
    39  
    40  	a.Nil(OptUpdateTransitConfig(cfg)(empty))
    41  
    42  	a.True(empty.Exportable)
    43  	a.True(empty.AllowPlaintextBackup)
    44  }
    45  
    46  func TestTransitCreateOptMisc(t *testing.T) {
    47  	a := assert.New(t)
    48  	empty := &CreateTransitKeyConfig{}
    49  
    50  	a.Nil(OptCreateTransitDerived()(empty))
    51  	a.True(empty.Derived)
    52  
    53  	empty.Derived = false
    54  
    55  	a.Nil(OptCreateTransitConvergent()(empty))
    56  	a.True(empty.Derived)
    57  	a.True(empty.Convergent)
    58  
    59  	a.Nil(OptCreateTransitAllowPlaintextBackup()(empty))
    60  	a.True(empty.AllowPlaintextBackup)
    61  
    62  	a.Nil(OptCreateTransitExportable()(empty))
    63  	a.True(empty.Exportable)
    64  
    65  	err := OptCreateTransitType("not a real type")(empty)
    66  	a.NotNil(err)
    67  
    68  	err = OptCreateTransitType(TypeCHACHA20POLY1305)(empty)
    69  	a.Nil(err)
    70  	a.Equal(TypeCHACHA20POLY1305, empty.Type)
    71  }
    72  
    73  func TestTransitUpdateOptMisc(t *testing.T) {
    74  	a := assert.New(t)
    75  	empty := &UpdateTransitKeyConfig{}
    76  
    77  	a.Nil(OptUpdateTransitDeletionAllowed(true)(empty))
    78  	a.True(*empty.DeletionAllowed)
    79  
    80  	a.Nil(OptUpdateTransitDeletionAllowed(false)(empty))
    81  	a.False(*empty.DeletionAllowed)
    82  
    83  	a.Nil(OptUpdateTransitAllowPlaintextBackup()(empty))
    84  	a.True(empty.AllowPlaintextBackup)
    85  
    86  	a.Nil(OptUpdateTransitExportable()(empty))
    87  	a.True(empty.Exportable)
    88  
    89  	a.Nil(OptUpdateTransitMinDecryptionVer(4)(empty))
    90  	a.Equal(4, empty.MinDecryptionVersion)
    91  
    92  	a.Nil(OptUpdateTransitMinEncryptionVer(5)(empty))
    93  	a.Equal(5, empty.MinEncryptionVersion)
    94  }