@@ -606,9 +606,7 @@ func (suite *basicSuite) TestDestwebhookTenantSecretManagement() {
606606 Path : "/" + tenantID + "/destinations/" + destinationID ,
607607 Body : map [string ]interface {}{
608608 "credentials" : map [string ]interface {}{
609- "secret" : "" , // test if empty string is allowed (should be yes)
610- "previous_secret" : "another-secret" ,
611- "previous_secret_invalid_at" : time .Now ().Add (24 * time .Hour ).Format (time .RFC3339 ),
609+ "previous_secret" : "another-secret" ,
612610 },
613611 },
614612 }, token ),
@@ -618,7 +616,7 @@ func (suite *basicSuite) TestDestwebhookTenantSecretManagement() {
618616 Body : map [string ]interface {}{
619617 "message" : "validation error" ,
620618 "data" : map [string ]interface {}{
621- "credentials.secret " : "required " ,
619+ "credentials.previous_secret " : "forbidden " ,
622620 },
623621 },
624622 },
@@ -641,7 +639,7 @@ func (suite *basicSuite) TestDestwebhookTenantSecretManagement() {
641639 Body : map [string ]interface {}{
642640 "message" : "validation error" ,
643641 "data" : map [string ]interface {}{
644- "credentials.secret " : "required " ,
642+ "credentials.previous_secret_invalid_at " : "forbidden " ,
645643 },
646644 },
647645 },
@@ -876,6 +874,9 @@ func (suite *basicSuite) TestDestwebhookAdminSecretManagement() {
876874 }
877875 suite .RunAPITests (suite .T (), createTests )
878876
877+ updatedPreviousSecret := secret + "_2"
878+ updatedPreviousSecretInvalidAt := time .Now ().Add (24 * time .Hour ).Format (time .RFC3339 )
879+
879880 // Second group: Test update flows using the destination with custom secret
880881 updateTests := []APITest {
881882 {
@@ -944,18 +945,16 @@ func (suite *basicSuite) TestDestwebhookAdminSecretManagement() {
944945 Path : "/" + tenantID + "/destinations/" + destinationID ,
945946 Body : map [string ]interface {}{
946947 "credentials" : map [string ]interface {}{
947- "secret" : newSecret ,
948- "previous_secret" : secret ,
948+ "previous_secret" : updatedPreviousSecret ,
949949 },
950950 },
951951 }),
952952 Expected : APITestExpectation {
953953 Match : & httpclient.Response {
954- StatusCode : http .StatusUnprocessableEntity ,
954+ StatusCode : http .StatusOK ,
955955 Body : map [string ]interface {}{
956- "message" : "validation error" ,
957- "data" : map [string ]interface {}{
958- "credentials.previous_secret_invalid_at" : "required" ,
956+ "credentials" : map [string ]interface {}{
957+ "previous_secret" : updatedPreviousSecret ,
959958 },
960959 },
961960 },
@@ -968,25 +967,24 @@ func (suite *basicSuite) TestDestwebhookAdminSecretManagement() {
968967 Path : "/" + tenantID + "/destinations/" + destinationID ,
969968 Body : map [string ]interface {}{
970969 "credentials" : map [string ]interface {}{
971- "secret" : newSecret ,
972- "previous_secret_invalid_at" : time .Now ().Add (24 * time .Hour ).Format (time .RFC3339 ),
970+ "previous_secret_invalid_at" : updatedPreviousSecretInvalidAt ,
973971 },
974972 },
975973 }),
976974 Expected : APITestExpectation {
977975 Match : & httpclient.Response {
978- StatusCode : http .StatusUnprocessableEntity ,
976+ StatusCode : http .StatusOK ,
979977 Body : map [string ]interface {}{
980- "message " : "validation error" ,
981- "data " : map [ string ] interface {}{
982- "credentials.previous_secret " : "required" ,
978+ "credentials " : map [ string ] interface {}{
979+ "previous_secret " : updatedPreviousSecret ,
980+ "previous_secret_invalid_at " : updatedPreviousSecretInvalidAt ,
983981 },
984982 },
985983 },
986984 },
987985 },
988986 {
989- Name : "PATCH /:tenantID/destinations/:destinationID - set previous_secret directly " ,
987+ Name : "PATCH /:tenantID/destinations/:destinationID - overrides everything " ,
990988 Request : suite .AuthRequest (httpclient.Request {
991989 Method : httpclient .MethodPATCH ,
992990 Path : "/" + tenantID + "/destinations/" + destinationID ,
@@ -1072,6 +1070,7 @@ func (suite *basicSuite) TestDestwebhookAdminSecretManagement() {
10721070 Path : "/" + tenantID + "/destinations/" + destinationID ,
10731071 Body : map [string ]interface {}{
10741072 "credentials" : map [string ]interface {}{
1073+ "secret" : "" ,
10751074 "previous_secret" : secret ,
10761075 "previous_secret_invalid_at" : time .Now ().Add (24 * time .Hour ).Format (time .RFC3339 ),
10771076 },
@@ -1133,6 +1132,59 @@ func (suite *basicSuite) TestDestwebhookAdminSecretManagement() {
11331132 },
11341133 },
11351134 },
1135+ {
1136+ Name : "PATCH /:tenantID/destinations/:destinationID - admin unset previous_secret" ,
1137+ Request : suite .AuthRequest (httpclient.Request {
1138+ Method : httpclient .MethodPATCH ,
1139+ Path : "/" + tenantID + "/destinations/" + destinationID ,
1140+ Body : map [string ]interface {}{
1141+ "credentials" : map [string ]interface {}{
1142+ "previous_secret" : "" ,
1143+ "previous_secret_invalid_at" : "" ,
1144+ },
1145+ },
1146+ }),
1147+ Expected : APITestExpectation {
1148+ Match : & httpclient.Response {
1149+ StatusCode : http .StatusOK ,
1150+ },
1151+ },
1152+ },
1153+ {
1154+ Name : "GET /:tenantID/destinations/:destinationID - verify previous_secret was unset" ,
1155+ Request : suite .AuthRequest (httpclient.Request {
1156+ Method : httpclient .MethodGET ,
1157+ Path : "/" + tenantID + "/destinations/" + destinationID ,
1158+ }),
1159+ Expected : APITestExpectation {
1160+ Validate : map [string ]interface {}{
1161+ "type" : "object" ,
1162+ "properties" : map [string ]interface {}{
1163+ "statusCode" : map [string ]interface {}{
1164+ "const" : 200 ,
1165+ },
1166+ "body" : map [string ]interface {}{
1167+ "type" : "object" ,
1168+ "required" : []interface {}{"credentials" },
1169+ "properties" : map [string ]interface {}{
1170+ "credentials" : map [string ]interface {}{
1171+ "type" : "object" ,
1172+ "required" : []interface {}{"secret" },
1173+ "properties" : map [string ]interface {}{
1174+ "secret" : map [string ]interface {}{
1175+ "type" : "string" ,
1176+ "minLength" : 32 ,
1177+ "pattern" : "^[a-zA-Z0-9]+$" ,
1178+ },
1179+ },
1180+ "additionalProperties" : false ,
1181+ },
1182+ },
1183+ },
1184+ },
1185+ },
1186+ },
1187+ },
11361188 }
11371189 suite .RunAPITests (suite .T (), updateTests )
11381190
0 commit comments