@@ -30,11 +30,12 @@ type mergeInputCase struct {
30
30
}
31
31
32
32
type newAgentConfigCase struct {
33
- msg string
34
- expectError bool
35
- input func (* Config )
36
- logOptions func (t * testing.T ) []log.Option
37
- test func (* testing.T , * agent.Config )
33
+ msg string
34
+ expectError bool
35
+ requireErrorPrefix string
36
+ input func (* Config )
37
+ logOptions func (t * testing.T ) []log.Option
38
+ test func (* testing.T , * agent.Config )
38
39
}
39
40
40
41
func TestDownloadTrustBundle (t * testing.T ) {
@@ -677,6 +678,9 @@ func TestNewAgentConfig(t *testing.T) {
677
678
{
678
679
msg : "insecure_bootstrap should be correctly set to true" ,
679
680
input : func (c * Config ) {
681
+ // in this case, remove trust_bundle_path provided by defaultValidConfig()
682
+ // because trust_bundle_path and insecure_bootstrap cannot be set at the same time
683
+ c .Agent .TrustBundlePath = ""
680
684
c .Agent .InsecureBootstrap = true
681
685
},
682
686
test : func (t * testing.T , c * agent.Config ) {
@@ -730,8 +734,9 @@ func TestNewAgentConfig(t *testing.T) {
730
734
},
731
735
},
732
736
{
733
- msg : "trust_bundle_path and trust_bundle_url cannot both be set" ,
734
- expectError : true ,
737
+ msg : "trust_bundle_path and trust_bundle_url cannot both be set" ,
738
+ expectError : true ,
739
+ requireErrorPrefix : "only one of trust_bundle_url or trust_bundle_path can be specified, not both" ,
735
740
input : func (c * Config ) {
736
741
c .Agent .TrustBundlePath = "foo"
737
742
c .Agent .TrustBundleURL = "foo2"
@@ -741,10 +746,66 @@ func TestNewAgentConfig(t *testing.T) {
741
746
},
742
747
},
743
748
{
744
- msg : "insecure_bootstrap and trust_bundle_url cannot both be set" ,
745
- expectError : true ,
749
+ msg : "insecure_bootstrap and trust_bundle_path cannot both be set" ,
750
+ expectError : true ,
751
+ requireErrorPrefix : "only one of insecure_bootstrap or trust_bundle_path can be specified, not both" ,
746
752
input : func (c * Config ) {
753
+ c .Agent .TrustBundlePath = "foo"
754
+ c .Agent .InsecureBootstrap = true
755
+ },
756
+ test : func (t * testing.T , c * agent.Config ) {
757
+ require .Nil (t , c )
758
+ },
759
+ },
760
+ {
761
+ msg : "insecure_bootstrap and trust_bundle_url cannot both be set" ,
762
+ expectError : true ,
763
+ requireErrorPrefix : "only one of insecure_bootstrap or trust_bundle_url can be specified, not both" ,
764
+ input : func (c * Config ) {
765
+ // in this case, remove trust_bundle_path provided by defaultValidConfig()
766
+ c .Agent .TrustBundlePath = ""
747
767
c .Agent .TrustBundleURL = "foo"
768
+ c .Agent .InsecureBootstrap = true
769
+ },
770
+ test : func (t * testing.T , c * agent.Config ) {
771
+ require .Nil (t , c )
772
+ },
773
+ },
774
+ {
775
+ msg : "insecure_bootstrap, trust_bundle_url, trust_bundle_path cannot be set at the same time" ,
776
+ expectError : true ,
777
+ requireErrorPrefix : "only one of insecure_bootstrap, trust_bundle_url, or trust_bundle_path can be specified, not the three options" ,
778
+ input : func (c * Config ) {
779
+ c .Agent .TrustBundlePath = "bar"
780
+ c .Agent .TrustBundleURL = "foo"
781
+ c .Agent .InsecureBootstrap = true
782
+ },
783
+ test : func (t * testing.T , c * agent.Config ) {
784
+ require .Nil (t , c )
785
+ },
786
+ },
787
+ {
788
+ msg : "trust_bundle_path or trust_bundle_url must be configured unless insecure_bootstrap is set" ,
789
+ expectError : true ,
790
+ requireErrorPrefix : "trust_bundle_path or trust_bundle_url must be configured unless insecure_bootstrap is set" ,
791
+ input : func (c * Config ) {
792
+ // in this case, remove trust_bundle_path provided by defaultValidConfig()
793
+ c .Agent .TrustBundlePath = ""
794
+ c .Agent .TrustBundleURL = ""
795
+ c .Agent .InsecureBootstrap = false
796
+ },
797
+ test : func (t * testing.T , c * agent.Config ) {
798
+ require .Nil (t , c )
799
+ },
800
+ },
801
+ {
802
+ msg : "trust_bundle_url must start with https://" ,
803
+ expectError : true ,
804
+ requireErrorPrefix : "trust bundle URL must start with https://" ,
805
+ input : func (c * Config ) {
806
+ // remove trust_bundle_path provided by defaultValidConfig()
807
+ c .Agent .TrustBundlePath = ""
808
+ c .Agent .TrustBundleURL = "foo.bar"
748
809
c .Agent .InsecureBootstrap = false
749
810
},
750
811
test : func (t * testing.T , c * agent.Config ) {
@@ -931,6 +992,9 @@ func TestNewAgentConfig(t *testing.T) {
931
992
ac , err := NewAgentConfig (input , logOpts , false )
932
993
if testCase .expectError {
933
994
require .Error (t , err )
995
+ if testCase .requireErrorPrefix != "" {
996
+ spiretest .RequireErrorPrefix (t , err , testCase .requireErrorPrefix )
997
+ }
934
998
} else {
935
999
require .NoError (t , err )
936
1000
}
0 commit comments