nulogy_message_bus_producer 3.4.0 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -27
  3. data/lib/nulogy_message_bus_producer/config.rb +1 -1
  4. data/lib/nulogy_message_bus_producer/self_serve_subscription.rb +18 -0
  5. data/lib/nulogy_message_bus_producer/subscriptions/configured_subscription.rb +14 -0
  6. data/lib/nulogy_message_bus_producer/subscriptions/finder.rb +2 -2
  7. data/lib/nulogy_message_bus_producer/subscriptions/postgres_transport.rb +4 -4
  8. data/lib/nulogy_message_bus_producer/subscriptions/query_validator.rb +1 -1
  9. data/lib/nulogy_message_bus_producer/subscriptions/valid_for_schema_validator.rb +14 -0
  10. data/lib/nulogy_message_bus_producer/version.rb +1 -1
  11. data/lib/nulogy_message_bus_producer.rb +7 -4
  12. data/spec/dummy/bin/setup +8 -9
  13. data/spec/dummy/bin/yarn +15 -7
  14. data/spec/dummy/config/application.rb +11 -6
  15. data/spec/dummy/config/boot.rb +2 -4
  16. data/spec/dummy/config/cable.yml +2 -2
  17. data/spec/dummy/config/environments/development.rb +29 -7
  18. data/spec/dummy/config/environments/production.rb +45 -15
  19. data/spec/dummy/config/environments/test.rb +24 -7
  20. data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
  21. data/spec/dummy/config/initializers/content_security_policy.rb +30 -0
  22. data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
  23. data/spec/dummy/config/initializers/new_framework_defaults_6_1.rb +67 -0
  24. data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
  25. data/spec/dummy/config/locales/en.yml +1 -1
  26. data/spec/dummy/config/storage.yml +34 -0
  27. data/spec/dummy/config.ru +1 -0
  28. data/spec/integration/lib/nulogy_message_bus_producer/repopulate_replication_slots_spec.rb +1 -1
  29. data/spec/integration/lib/nulogy_message_bus_producer/subscription_spec.rb +3 -75
  30. data/spec/integration_spec_helper.rb +0 -6
  31. data/spec/nulogy_message_bus_producer/subscriptions/subscription_spec.rb +9 -0
  32. data/spec/spec_helper.rb +5 -0
  33. data/spec/support/shared_examples/subscription_validations.rb +77 -0
  34. data/spec/support/skip.rb +9 -0
  35. data/spec/support/sql_helpers.rb +1 -1
  36. data/spec/support/subscription_helpers.rb +2 -2
  37. data/spec/support/test_graphql_schema.rb +0 -2
  38. metadata +110 -64
  39. data/lib/nulogy_message_bus_producer/subscription.rb +0 -30
  40. data/spec/dummy/log/development.log +0 -2333
  41. data/spec/dummy/log/test.log +0 -44636
@@ -1,7 +1,8 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
- # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
4
+ # Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) }
5
5
 
6
- # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
- # Rails.backtrace_cleaner.remove_silencers!
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code
7
+ # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'".
8
+ Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"]
@@ -0,0 +1,30 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Define an application-wide content security policy
4
+ # For further information see the following documentation
5
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
6
+
7
+ # Rails.application.config.content_security_policy do |policy|
8
+ # policy.default_src :self, :https
9
+ # policy.font_src :self, :https, :data
10
+ # policy.img_src :self, :https, :data
11
+ # policy.object_src :none
12
+ # policy.script_src :self, :https
13
+ # policy.style_src :self, :https
14
+ # # If you are using webpack-dev-server then specify webpack-dev-server host
15
+ # policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
16
+
17
+ # # Specify URI for violation reports
18
+ # # policy.report_uri "/csp-violation-report-endpoint"
19
+ # end
20
+
21
+ # If you are using UJS then enable automatic nonce generation
22
+ # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
23
+
24
+ # Set the nonce only to specific directives
25
+ # Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
26
+
27
+ # Report CSP violations to a specified URI
28
+ # For further information see the following documentation:
29
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
30
+ # Rails.application.config.content_security_policy_report_only = true
@@ -1,4 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  # Configure sensitive parameters which will be filtered from the log file.
4
- Rails.application.config.filter_parameters += [:password]
4
+ Rails.application.config.filter_parameters += [
5
+ :password, :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
6
+ ]
@@ -0,0 +1,67 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains migration options to ease your Rails 6.1 upgrade.
4
+ #
5
+ # Once upgraded flip defaults one by one to migrate to the new default.
6
+ #
7
+ # Read the Guide for Upgrading Ruby on Rails for more info on each option.
8
+
9
+ # Support for inversing belongs_to -> has_many Active Record associations.
10
+ # Rails.application.config.active_record.has_many_inversing = true
11
+
12
+ # Track Active Storage variants in the database.
13
+ # Rails.application.config.active_storage.track_variants = true
14
+
15
+ # Apply random variation to the delay when retrying failed jobs.
16
+ # Rails.application.config.active_job.retry_jitter = 0.15
17
+
18
+ # Stop executing `after_enqueue`/`after_perform` callbacks if
19
+ # `before_enqueue`/`before_perform` respectively halts with `throw :abort`.
20
+ # Rails.application.config.active_job.skip_after_callbacks_if_terminated = true
21
+
22
+ # Specify cookies SameSite protection level: either :none, :lax, or :strict.
23
+ #
24
+ # This change is not backwards compatible with earlier Rails versions.
25
+ # It's best enabled when your entire app is migrated and stable on 6.1.
26
+ # Rails.application.config.action_dispatch.cookies_same_site_protection = :lax
27
+
28
+ # Generate CSRF tokens that are encoded in URL-safe Base64.
29
+ #
30
+ # This change is not backwards compatible with earlier Rails versions.
31
+ # It's best enabled when your entire app is migrated and stable on 6.1.
32
+ # Rails.application.config.action_controller.urlsafe_csrf_tokens = true
33
+
34
+ # Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an
35
+ # UTC offset or a UTC time.
36
+ # ActiveSupport.utc_to_local_returns_utc_offset_times = true
37
+
38
+ # Change the default HTTP status code to `308` when redirecting non-GET/HEAD
39
+ # requests to HTTPS in `ActionDispatch::SSL` middleware.
40
+ # Rails.application.config.action_dispatch.ssl_default_redirect_status = 308
41
+
42
+ # Use new connection handling API. For most applications this won't have any
43
+ # effect. For applications using multiple databases, this new API provides
44
+ # support for granular connection swapping.
45
+ # Rails.application.config.active_record.legacy_connection_handling = false
46
+
47
+ # Make `form_with` generate non-remote forms by default.
48
+ # Rails.application.config.action_view.form_with_generates_remote_forms = false
49
+
50
+ # Set the default queue name for the analysis job to the queue adapter default.
51
+ # Rails.application.config.active_storage.queues.analysis = nil
52
+
53
+ # Set the default queue name for the purge job to the queue adapter default.
54
+ # Rails.application.config.active_storage.queues.purge = nil
55
+
56
+ # Set the default queue name for the incineration job to the queue adapter default.
57
+ # Rails.application.config.action_mailbox.queues.incineration = nil
58
+
59
+ # Set the default queue name for the routing job to the queue adapter default.
60
+ # Rails.application.config.action_mailbox.queues.routing = nil
61
+
62
+ # Set the default queue name for the mail deliver job to the queue adapter default.
63
+ # Rails.application.config.action_mailer.deliver_later_queue_name = nil
64
+
65
+ # Generate a `Link` header that gives a hint to modern browsers about
66
+ # preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`.
67
+ # Rails.application.config.action_view.preload_links_header = true
@@ -0,0 +1,11 @@
1
+ # Define an application-wide HTTP permissions policy. For further
2
+ # information see https://developers.google.com/web/updates/2018/06/feature-policy
3
+ #
4
+ # Rails.application.config.permissions_policy do |f|
5
+ # f.camera :none
6
+ # f.gyroscope :none
7
+ # f.microphone :none
8
+ # f.usb :none
9
+ # f.fullscreen :self
10
+ # f.payment :self, "https://secure.example.com"
11
+ # end
@@ -27,7 +27,7 @@
27
27
  # 'true': 'foo'
28
28
  #
29
29
  # To learn more, please read the Rails Internationalization guide
30
- # available at http://guides.rubyonrails.org/i18n.html.
30
+ # available at https://guides.rubyonrails.org/i18n.html.
31
31
 
32
32
  en:
33
33
  hello: "Hello world"
@@ -0,0 +1,34 @@
1
+ test:
2
+ service: Disk
3
+ root: <%= Rails.root.join("tmp/storage") %>
4
+
5
+ local:
6
+ service: Disk
7
+ root: <%= Rails.root.join("storage") %>
8
+
9
+ # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10
+ # amazon:
11
+ # service: S3
12
+ # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13
+ # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14
+ # region: us-east-1
15
+ # bucket: your_own_bucket
16
+
17
+ # Remember not to checkin your GCS keyfile to a repository
18
+ # google:
19
+ # service: GCS
20
+ # project: your_project
21
+ # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22
+ # bucket: your_own_bucket
23
+
24
+ # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25
+ # microsoft:
26
+ # service: AzureStorage
27
+ # storage_account_name: your_account_name
28
+ # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29
+ # container: your_container_name
30
+
31
+ # mirror:
32
+ # service: Mirror
33
+ # primary: local
34
+ # mirrors: [ amazon, google, microsoft ]
data/spec/dummy/config.ru CHANGED
@@ -3,3 +3,4 @@
3
3
  require_relative "config/environment"
4
4
 
5
5
  run Rails.application
6
+ Rails.application.load_server
@@ -14,7 +14,7 @@ RSpec.describe NulogyMessageBusProducer::RepopulateReplicationSlots do
14
14
  cleanup_everything
15
15
  end
16
16
 
17
- it "generates events" do
17
+ it "generates events", skip: flakey_in_ci do
18
18
  Kafka.create_topic(topic_name)
19
19
  consumer = Kafka.setup_kafka_consumer(topic_name)
20
20
 
@@ -1,79 +1,7 @@
1
1
  require "integration_spec_helper"
2
2
 
3
- RSpec.describe NulogyMessageBusProducer::Subscription do
4
- context "when validating" do
5
- it "is invalid without an id" do
6
- model = build_subscription(id: "")
7
-
8
- model.validate
9
-
10
- expect(model.errors[:id]).to contain_exactly("can't be blank")
11
- end
12
-
13
- it "is invalid without a subscription_group_id" do
14
- model = build_subscription(subscription_group_id: "")
15
-
16
- model.validate
17
-
18
- expect(model.errors[:subscription_group_id]).to contain_exactly("can't be blank")
19
- end
20
-
21
- it "is invalid with a blank query" do
22
- model = build_subscription(query: "")
23
-
24
- model.validate
25
-
26
- expect(model.errors[:query]).to contain_exactly("can't be blank")
27
- end
28
-
29
- it "is invalid with blank schema_key" do
30
- model = build_subscription(schema_key: "")
31
-
32
- model.validate
33
-
34
- expect(model.errors[:schema_key]).to contain_exactly("can't be blank")
35
- end
36
-
37
- it "is invalid with an invalid schema_key" do
38
- model = build_subscription(schema_key: "invalid")
39
-
40
- model.validate
41
-
42
- expect(model.errors[:query]).to contain_exactly(/Could not find a schema for schema_key 'invalid'/)
43
- end
44
-
45
- it "is invalid with an invalid query" do
46
- model = build_subscription(
47
- query: subscription_query(query: "foo { a_field_that_does_not_exist }")
48
- )
49
-
50
- model.validate
51
-
52
- expect(model).not_to be_valid
53
- expect(model.errors[:query]).to contain_exactly(
54
- match(/Field 'a_field_that_does_not_exist' doesn't exist on type 'testObject'/)
55
- )
56
- end
57
-
58
- it "valid with a valid query" do
59
- model = build_subscription(
60
- query: subscription_query(query: "foo { id }")
61
- )
62
-
63
- model.validate
64
-
65
- expect(model.errors).not_to include(:query)
66
- end
67
- end
68
-
69
- def build_subscription(overrides = {})
70
- attrs = {
71
- id: SecureRandom.uuid,
72
- subscription_group_id: SecureRandom.uuid,
73
- schema_key: "test",
74
- query: subscription_query,
75
- }.merge(overrides)
76
-
77
- NulogyMessageBusProducer::Subscription.new(attrs)
3
+ module NulogyMessageBusProducer
4
+ RSpec.describe SelfServeSubscription do
5
+ include_examples "subscription validations"
78
6
  end
79
7
  end
@@ -1,6 +1,3 @@
1
- # Make all rspec configuration changes to this file.
2
- # Leave automatically generated configuration files untouched to facilitate gem upgrades.
3
-
4
1
  ENV["RAILS_ENV"] ||= "test"
5
2
 
6
3
  require File.expand_path("dummy/config/environment.rb", __dir__)
@@ -10,8 +7,6 @@ require "rspec/json_expectations"
10
7
  require "active_record"
11
8
  require "spec_helper"
12
9
 
13
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
14
-
15
10
  RSpec.configure do |config|
16
11
  # Uncomment this line to see full backtraces for spec failures
17
12
  # config.backtrace_exclusion_patterns = []
@@ -37,5 +32,4 @@ RSpec.configure do |config|
37
32
 
38
33
  config.include(SpecUtils)
39
34
  config.include(SqlHelpers)
40
- config.include(SubscriptionHelpers)
41
35
  end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ module NulogyMessageBusProducer
4
+ module Subscriptions
5
+ RSpec.describe ConfiguredSubscription do
6
+ include_examples "subscription validations"
7
+ end
8
+ end
9
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require "rails/all"
2
2
  require "nulogy_message_bus_producer"
3
3
 
4
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
5
+
4
6
  RSpec.configure do |config|
5
7
  config.expect_with(:rspec) do |expectations|
6
8
  # This is generally recommended, and will default to `true` in RSpec 4.
@@ -52,4 +54,7 @@ RSpec.configure do |config|
52
54
  example.run
53
55
  end
54
56
  end
57
+
58
+ config.include(SubscriptionHelpers)
59
+ config.extend(Skip)
55
60
  end
@@ -0,0 +1,77 @@
1
+ RSpec.shared_examples "subscription validations" do
2
+ context "when validating" do
3
+ it "is invalid without an id" do
4
+ model = build_subscription(id: "")
5
+
6
+ model.validate
7
+
8
+ expect(model.errors[:id]).to contain_exactly("can't be blank")
9
+ end
10
+
11
+ it "is invalid without a subscription_group_id" do
12
+ model = build_subscription(subscription_group_id: "")
13
+
14
+ model.validate
15
+
16
+ expect(model.errors[:subscription_group_id]).to contain_exactly("can't be blank")
17
+ end
18
+
19
+ it "is invalid with a blank query" do
20
+ model = build_subscription(query: "")
21
+
22
+ model.validate
23
+
24
+ expect(model.errors[:query]).to contain_exactly("can't be blank")
25
+ end
26
+
27
+ it "is invalid with blank schema_key" do
28
+ model = build_subscription(schema_key: "")
29
+
30
+ model.validate
31
+
32
+ expect(model.errors[:schema_key]).to contain_exactly("can't be blank")
33
+ end
34
+
35
+ it "is invalid with an invalid schema_key" do
36
+ model = build_subscription(schema_key: "invalid")
37
+
38
+ model.validate
39
+
40
+ expect(model.errors[:query]).to contain_exactly(/Could not find a schema for schema_key 'invalid'/)
41
+ end
42
+
43
+ it "is invalid with an invalid query" do
44
+ model = build_subscription(
45
+ query: subscription_query(query: "foo { a_field_that_does_not_exist }")
46
+ )
47
+
48
+ model.validate
49
+
50
+ expect(model).not_to be_valid
51
+ expect(model.errors[:query]).to contain_exactly(
52
+ match(/Field 'a_field_that_does_not_exist' doesn't exist on type 'testObject'/)
53
+ )
54
+ end
55
+
56
+ it "valid with a valid query" do
57
+ model = build_subscription(
58
+ query: subscription_query(query: "foo { id }")
59
+ )
60
+
61
+ model.validate
62
+
63
+ expect(model.errors).not_to include(:query)
64
+ end
65
+ end
66
+
67
+ def build_subscription(overrides = {})
68
+ attrs = {
69
+ id: SecureRandom.uuid,
70
+ subscription_group_id: SecureRandom.uuid,
71
+ schema_key: "test",
72
+ query: subscription_query
73
+ }.merge(overrides)
74
+
75
+ described_class.new(attrs)
76
+ end
77
+ end
@@ -0,0 +1,9 @@
1
+ module Skip
2
+ def flakey_in_ci
3
+ if ENV.fetch("CI", false)
4
+ "This spec is terribly flakey in CI, so we only run it locally"
5
+ else
6
+ false
7
+ end
8
+ end
9
+ end
@@ -14,7 +14,7 @@ module SqlHelpers
14
14
 
15
15
  # Just incase these models weren't loaded, do them explicitly
16
16
  ActiveRecord::Base.connection.execute("TRUNCATE #{NulogyMessageBusProducer::SubscriptionEvent.table_name}")
17
- ActiveRecord::Base.connection.execute("TRUNCATE #{NulogyMessageBusProducer::Subscription.table_name}")
17
+ ActiveRecord::Base.connection.execute("TRUNCATE #{NulogyMessageBusProducer::SelfServeSubscription.table_name}")
18
18
  end
19
19
 
20
20
  def replication_slots
@@ -9,9 +9,9 @@ module SubscriptionHelpers
9
9
  expect {
10
10
  gql_response = execute_graphql(gql, schema)
11
11
  expect(gql_response).to eq(data: {})
12
- }.to change(NulogyMessageBusProducer::Subscription, :count).by(1)
12
+ }.to change(NulogyMessageBusProducer::SelfServeSubscription, :count).by(1)
13
13
 
14
- NulogyMessageBusProducer::Subscription.find(subscription_id)
14
+ NulogyMessageBusProducer::SelfServeSubscription.find(subscription_id)
15
15
  end
16
16
 
17
17
  def configured_subscription(
@@ -40,8 +40,6 @@ module NulogyMessageBusProducer
40
40
  end
41
41
 
42
42
  class TestSchema < GraphQL::Schema
43
- use GraphQL::Execution::Interpreter
44
- use GraphQL::Analysis::AST
45
43
  use NulogyMessageBusProducer::Subscriptions::PostgresTransport
46
44
 
47
45
  query TestQuery