Skip to content

Commit

Permalink
Check
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Hume committed Nov 27, 2023
1 parent 4baabf8 commit c39c31f
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 75 deletions.
5 changes: 3 additions & 2 deletions integration/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ resource "materialize_cluster" "cluster_source" {
}

resource "materialize_cluster" "cluster_sink" {
name = "cluster_sinks"
size = "3xsmall"
name = "cluster_sinks"
size = "3xsmall"
replication_factor = 1
}

resource "materialize_cluster_grant" "cluster_grant_usage" {
Expand Down
21 changes: 17 additions & 4 deletions pkg/materialize/source_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ var sourceWebhook = MaterializeObject{Name: "webhook_source", SchemaName: "schem
func TestSourceWebhookCreateExposeHeaders(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(
`CREATE SOURCE "database"."schema"."webhook_source" IN CLUSTER "cluster" FROM WEBHOOK BODY FORMAT JSON INCLUDE HEADER 'timestamp' AS ts INCLUDE HEADER 'x-event-type' AS event_type;`,
`CREATE SOURCE "database"."schema"."webhook_source"
IN CLUSTER "cluster"
FROM WEBHOOK BODY FORMAT JSON INCLUDE HEADER 'timestamp' AS ts
INCLUDE HEADER 'x-event-type' AS event_type;`,
).WillReturnResult(sqlmock.NewResult(1, 1))

var includeHeader = []HeaderStruct{
Expand Down Expand Up @@ -41,7 +44,9 @@ func TestSourceWebhookCreateExposeHeaders(t *testing.T) {
func TestSourceWebhookCreateIncludeHeaders(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(
`CREATE SOURCE "database"."schema"."webhook_source" IN CLUSTER "cluster" FROM WEBHOOK BODY FORMAT JSON INCLUDE HEADERS \(NOT 'authorization', NOT 'x-api-key'\);`,
`CREATE SOURCE "database"."schema"."webhook_source"
IN CLUSTER "cluster"
FROM WEBHOOK BODY FORMAT JSON INCLUDE HEADERS \(NOT 'authorization', NOT 'x-api-key'\);`,
).WillReturnResult(sqlmock.NewResult(1, 1))

b := NewSourceWebhookBuilder(db, sourceWebhook)
Expand All @@ -60,7 +65,11 @@ func TestSourceWebhookCreateIncludeHeaders(t *testing.T) {
func TestSourceWebhookCreateValidated(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(
`CREATE SOURCE "database"."schema"."webhook_source" IN CLUSTER "cluster" FROM WEBHOOK BODY FORMAT JSON CHECK \( WITH \(HEADERS, BODY AS request_body, SECRET "database"."schema"."my_webhook_shared_secret"\) decode\(headers->'x-signature', 'base64'\) = hmac\(request_body, my_webhook_shared_secret, 'sha256'\)\);`,
`CREATE SOURCE "database"."schema"."webhook_source"
IN CLUSTER "cluster"
FROM WEBHOOK BODY FORMAT JSON CHECK
\( WITH \(HEADERS, BODY AS request_body, SECRET "database"."schema"."my_webhook_shared_secret"\)
decode\(headers->'x-signature', 'base64'\) = hmac\(request_body, my_webhook_shared_secret, 'sha256'\)\);`,
).WillReturnResult(sqlmock.NewResult(1, 1))

var checkOptions = []CheckOptionsStruct{
Expand Down Expand Up @@ -97,7 +106,11 @@ func TestSourceWebhookCreateValidated(t *testing.T) {
func TestSourceWebhookCreateSegment(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(
`CREATE SOURCE "database"."schema"."webhook_source" IN CLUSTER "cluster" FROM WEBHOOK BODY FORMAT JSON INCLUDE HEADER 'event-type' AS event_type INCLUDE HEADERS CHECK \( WITH \(BODY BYTES, HEADERS, SECRET "database"."schema"."my_webhook_shared_secret" AS secret BYTES\) decode\(headers->'x-signature', 'hex'\) = hmac\(body, secret, 'sha1'\)\);`,
`CREATE SOURCE "database"."schema"."webhook_source"
IN CLUSTER "cluster"
FROM WEBHOOK BODY FORMAT JSON INCLUDE HEADER 'event-type' AS event_type INCLUDE HEADERS CHECK
\( WITH \(BODY BYTES, HEADERS, SECRET "database"."schema"."my_webhook_shared_secret" AS secret BYTES\)
decode\(headers->'x-signature', 'hex'\) = hmac\(body, secret, 'sha1'\)\);`,
).WillReturnResult(sqlmock.NewResult(1, 1))

var includeHeader = []HeaderStruct{
Expand Down
Loading

0 comments on commit c39c31f

Please sign in to comment.