@@ -6829,6 +6829,123 @@ func TestProperAuthing(t *testing.T) {
6829
6829
}
6830
6830
}
6831
6831
6832
+ func TestPatchIssuer (t * testing.T ) {
6833
+ t .Parallel ()
6834
+
6835
+ type TestCase struct {
6836
+ Field string
6837
+ Before interface {}
6838
+ Patched interface {}
6839
+ }
6840
+ testCases := []TestCase {
6841
+ {
6842
+ Field : "issuer_name" ,
6843
+ Before : "root" ,
6844
+ Patched : "root-new" ,
6845
+ },
6846
+ {
6847
+ Field : "leaf_not_after_behavior" ,
6848
+ Before : "err" ,
6849
+ Patched : "permit" ,
6850
+ },
6851
+ {
6852
+ Field : "usage" ,
6853
+ Before : "crl-signing,issuing-certificates,ocsp-signing,read-only" ,
6854
+ Patched : "issuing-certificates,read-only" ,
6855
+ },
6856
+ {
6857
+ Field : "revocation_signature_algorithm" ,
6858
+ Before : "ECDSAWithSHA256" ,
6859
+ Patched : "ECDSAWithSHA384" ,
6860
+ },
6861
+ {
6862
+ Field : "issuing_certificates" ,
6863
+ Before : []string {"http://localhost/v1/pki-1/ca" },
6864
+ Patched : []string {"http://localhost/v1/pki/ca" },
6865
+ },
6866
+ {
6867
+ Field : "crl_distribution_points" ,
6868
+ Before : []string {"http://localhost/v1/pki-1/crl" },
6869
+ Patched : []string {"http://localhost/v1/pki/crl" },
6870
+ },
6871
+ {
6872
+ Field : "ocsp_servers" ,
6873
+ Before : []string {"http://localhost/v1/pki-1/ocsp" },
6874
+ Patched : []string {"http://localhost/v1/pki/ocsp" },
6875
+ },
6876
+ {
6877
+ Field : "enable_aia_url_templating" ,
6878
+ Before : false ,
6879
+ Patched : true ,
6880
+ },
6881
+ {
6882
+ Field : "manual_chain" ,
6883
+ Before : []string (nil ),
6884
+ Patched : []string {"self" },
6885
+ },
6886
+ }
6887
+
6888
+ for index , testCase := range testCases {
6889
+ t .Logf ("index: %v / tc: %v" , index , testCase )
6890
+
6891
+ b , s := CreateBackendWithStorage (t )
6892
+
6893
+ // 1. Setup root issuer.
6894
+ resp , err := CBWrite (b , s , "root/generate/internal" , map [string ]interface {}{
6895
+ "common_name" : "Vault Root CA" ,
6896
+ "key_type" : "ec" ,
6897
+ "ttl" : "7200h" ,
6898
+ "issuer_name" : "root" ,
6899
+ })
6900
+ requireSuccessNonNilResponse (t , resp , err , "failed generating root issuer" )
6901
+ id := string (resp .Data ["issuer_id" ].(issuerID ))
6902
+
6903
+ // 2. Enable Cluster paths
6904
+ resp , err = CBWrite (b , s , "config/urls" , map [string ]interface {}{
6905
+ "path" : "https://localhost/v1/pki" ,
6906
+ "aia_path" : "http://localhost/v1/pki" ,
6907
+ })
6908
+ requireSuccessNonNilResponse (t , resp , err , "failed updating AIA config" )
6909
+
6910
+ // 3. Add AIA information
6911
+ resp , err = CBPatch (b , s , "issuer/default" , map [string ]interface {}{
6912
+ "issuing_certificates" : "http://localhost/v1/pki-1/ca" ,
6913
+ "crl_distribution_points" : "http://localhost/v1/pki-1/crl" ,
6914
+ "ocsp_servers" : "http://localhost/v1/pki-1/ocsp" ,
6915
+ })
6916
+ requireSuccessNonNilResponse (t , resp , err , "failed setting up issuer" )
6917
+
6918
+ // 4. Read the issuer before.
6919
+ resp , err = CBRead (b , s , "issuer/default" )
6920
+ requireSuccessNonNilResponse (t , resp , err , "failed reading root issuer before" )
6921
+ require .Equal (t , testCase .Before , resp .Data [testCase .Field ], "bad expectations" )
6922
+
6923
+ // 5. Perform modification.
6924
+ resp , err = CBPatch (b , s , "issuer/default" , map [string ]interface {}{
6925
+ testCase .Field : testCase .Patched ,
6926
+ })
6927
+ requireSuccessNonNilResponse (t , resp , err , "failed patching root issuer" )
6928
+
6929
+ if testCase .Field != "manual_chain" {
6930
+ require .Equal (t , testCase .Patched , resp .Data [testCase .Field ], "failed persisting value" )
6931
+ } else {
6932
+ // self->id
6933
+ require .Equal (t , []string {id }, resp .Data [testCase .Field ], "failed persisting value" )
6934
+ }
6935
+
6936
+ // 6. Ensure it stuck
6937
+ resp , err = CBRead (b , s , "issuer/default" )
6938
+ requireSuccessNonNilResponse (t , resp , err , "failed reading root issuer after" )
6939
+
6940
+ if testCase .Field != "manual_chain" {
6941
+ require .Equal (t , testCase .Patched , resp .Data [testCase .Field ])
6942
+ } else {
6943
+ // self->id
6944
+ require .Equal (t , []string {id }, resp .Data [testCase .Field ], "failed persisting value" )
6945
+ }
6946
+ }
6947
+ }
6948
+
6832
6949
var (
6833
6950
initTest sync.Once
6834
6951
rsaCAKey string
0 commit comments