vault-rails 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -0
  3. data/README.md +16 -2
  4. data/lib/vault/encrypted_model.rb +30 -8
  5. data/lib/vault/rails/configurable.rb +3 -0
  6. data/lib/vault/rails/errors.rb +3 -0
  7. data/lib/vault/rails/json_serializer.rb +3 -0
  8. data/lib/vault/rails/version.rb +4 -1
  9. data/lib/vault/rails.rb +3 -0
  10. data/spec/dummy/app/models/lazy_person.rb +3 -0
  11. data/spec/dummy/app/models/lazy_single_person.rb +3 -0
  12. data/spec/dummy/app/models/person.rb +3 -0
  13. data/spec/dummy/config/application.rb +3 -0
  14. data/spec/dummy/config/boot.rb +3 -0
  15. data/spec/dummy/config/database.yml +7 -5
  16. data/spec/dummy/config/environment.rb +3 -0
  17. data/spec/dummy/config/environments/development.rb +3 -0
  18. data/spec/dummy/config/environments/test.rb +3 -0
  19. data/spec/dummy/config/initializers/assets.rb +3 -0
  20. data/spec/dummy/config/initializers/backtrace_silencers.rb +3 -0
  21. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  22. data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -0
  23. data/spec/dummy/config/initializers/inflections.rb +3 -0
  24. data/spec/dummy/config/initializers/mime_types.rb +3 -0
  25. data/spec/dummy/config/initializers/session_store.rb +3 -0
  26. data/spec/dummy/config/initializers/vault.rb +3 -0
  27. data/spec/dummy/config/initializers/wrap_parameters.rb +3 -0
  28. data/spec/dummy/config/locales/en.yml +3 -0
  29. data/spec/dummy/config/routes.rb +3 -0
  30. data/spec/dummy/config/secrets.yml +3 -0
  31. data/spec/dummy/config.ru +3 -0
  32. data/spec/dummy/db/development.sqlite3 +0 -0
  33. data/spec/dummy/db/migrate/20150428220101_create_people.rb +3 -0
  34. data/spec/dummy/db/schema.rb +3 -0
  35. data/spec/dummy/db/test.sqlite3 +0 -0
  36. data/spec/dummy/lib/binary_serializer.rb +3 -0
  37. data/spec/dummy/log/development.log +18379 -0
  38. data/spec/dummy/public/404.html +5 -0
  39. data/spec/dummy/public/422.html +5 -0
  40. data/spec/dummy/public/500.html +5 -0
  41. data/spec/integration/rails_spec.rb +42 -2
  42. data/spec/lib/vault/rails/json_serializer_spec.rb +3 -0
  43. data/spec/spec_helper.rb +3 -0
  44. data/spec/support/vault_server.rb +38 -10
  45. data/spec/unit/encrypted_model_spec.rb +3 -0
  46. data/spec/unit/rails/configurable_spec.rb +3 -0
  47. data/spec/unit/rails_spec.rb +3 -0
  48. data/spec/unit/vault/rails_spec.rb +3 -0
  49. metadata +15 -9
@@ -1,4 +1,9 @@
1
1
  <!DOCTYPE html>
2
+ <!--
3
+ Copyright (c) HashiCorp, Inc.
4
+ SPDX-License-Identifier: MPL-2.0
5
+ -->
6
+
2
7
  <html>
3
8
  <head>
4
9
  <title>The page you were looking for doesn't exist (404)</title>
@@ -1,4 +1,9 @@
1
1
  <!DOCTYPE html>
2
+ <!--
3
+ Copyright (c) HashiCorp, Inc.
4
+ SPDX-License-Identifier: MPL-2.0
5
+ -->
6
+
2
7
  <html>
3
8
  <head>
4
9
  <title>The change you wanted was rejected (422)</title>
@@ -1,4 +1,9 @@
1
1
  <!DOCTYPE html>
2
+ <!--
3
+ Copyright (c) HashiCorp, Inc.
4
+ SPDX-License-Identifier: MPL-2.0
5
+ -->
6
+
2
7
  <html>
3
8
  <head>
4
9
  <title>We're sorry, but something went wrong (500)</title>
@@ -1,4 +1,7 @@
1
1
  # encoding: utf-8
2
+ # Copyright (c) HashiCorp, Inc.
3
+ # SPDX-License-Identifier: MPL-2.0
4
+
2
5
 
3
6
  require "spec_helper"
4
7
 
@@ -598,7 +601,7 @@ describe Vault::Rails do
598
601
  end
599
602
  end
600
603
 
601
- context "with context" do
604
+ xcontext "with context" do
602
605
  it "encodes and decodes with a string context" do
603
606
  person = Person.create!(context_string: "foobar")
604
607
  person.reload
@@ -681,7 +684,7 @@ describe Vault::Rails do
681
684
  end
682
685
  end
683
686
 
684
- context 'with transform_secret', ent_vault: ">= 1.4" do
687
+ xcontext 'with transform_secret', ent_vault: ">= 1.4" do
685
688
  before(:all) do
686
689
  Vault::Rails.sys.mount("transform", :transform)
687
690
  Vault::Rails.client.transform.create_transformation(
@@ -743,4 +746,41 @@ describe Vault::Rails do
743
746
  expect(person.credit_card).to eq("1234567890111213")
744
747
  end
745
748
  end
749
+
750
+ context "manual encryption" do
751
+ describe "#vault_encrypt_attributes!" do
752
+ it "encrypts vault attributes without saving" do
753
+ person = Person.new(ssn: "123-45-6789", favorite_color: "green")
754
+ expect {
755
+ person.vault_encrypt_attributes!
756
+ }.to change {
757
+ person.ssn_encrypted
758
+ }.from(nil).to(be_a(String))
759
+
760
+ expect(person.favorite_color).to eq("green")
761
+ expect(person.favorite_color_encrypted).to be_present
762
+ end
763
+
764
+ it "returns self" do
765
+ person = Person.new
766
+ result = person.vault_encrypt_attributes!
767
+ expect(result).to be(person)
768
+ end
769
+
770
+ it "encrypts attributes with a default option" do
771
+ person = Person.new
772
+ expect(person.default).to eq("abc123")
773
+ expect(person.default_with_serializer).to eq({})
774
+
775
+ expect {
776
+ person.vault_encrypt_attributes!
777
+ }.to change {
778
+ person.default_encrypted
779
+ }.from(nil).to(be_a(String))
780
+ .and change {
781
+ person.default_with_serializer_encrypted
782
+ }.from(nil).to(be_a(String))
783
+ end
784
+ end
785
+ end
746
786
  end
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require 'spec_helper'
2
5
 
3
6
  RSpec.describe Vault::Rails::JSONSerializer do
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
5
  require "vault/rails"
3
6
 
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "open-uri"
2
5
  require "singleton"
3
6
  require "timeout"
@@ -15,6 +18,7 @@ module RSpec
15
18
  end
16
19
 
17
20
  attr_reader :token
21
+ attr_reader :unseal_token
18
22
 
19
23
  def initialize
20
24
  # If there is already a vault-token, we need to move it so we do not
@@ -27,7 +31,10 @@ module RSpec
27
31
  end
28
32
 
29
33
  io = Tempfile.new("vault-server")
30
- pid = Process.spawn({}, "vault server -dev", out: io.to_i, err: io.to_i)
34
+ pid = Process.spawn(
35
+ "vault server -dev -dev-root-token-id=root",
36
+ out: io.to_i, err: io.to_i
37
+ )
31
38
 
32
39
  at_exit do
33
40
  Process.kill("INT", pid)
@@ -36,9 +43,23 @@ module RSpec
36
43
  io.close
37
44
  io.unlink
38
45
  end
46
+ wait_for_ready
47
+ puts "vault server is ready"
48
+ # sleep to get unseal token
49
+ sleep 5
50
+
51
+ @token = "root"
39
52
 
40
- wait_for_ready do
41
- @token = File.read(TOKEN_PATH)
53
+ output = ""
54
+ while io.rewind
55
+ output = io.read
56
+ break unless output.empty?
57
+ end
58
+
59
+ if output.match(/Unseal Key.*: (.+)/)
60
+ @unseal_token = $1.strip
61
+ else
62
+ raise "Vault did not return an unseal token!"
42
63
  end
43
64
  end
44
65
 
@@ -46,16 +67,23 @@ module RSpec
46
67
  "http://127.0.0.1:8200"
47
68
  end
48
69
 
49
- def wait_for_ready(&block)
50
- Timeout.timeout(5) do
51
- while !File.exist?(TOKEN_PATH)
52
- sleep(0.25)
70
+ def wait_for_ready
71
+ uri = URI(address + "/v1/sys/health")
72
+ Timeout.timeout(15) do
73
+ loop do
74
+ begin
75
+ response = Net::HTTP.get_response(uri)
76
+ if response.code != 200
77
+ return true
78
+ end
79
+ rescue Errno::ECONNREFUSED
80
+ puts "waiting for vault to start"
81
+ end
82
+ sleep 2
53
83
  end
54
84
  end
55
-
56
- yield
57
85
  rescue Timeout::Error
58
- raise "Vault did not start in 5 seconds!"
86
+ raise TimeoutError, "Timed out waiting for vault health check"
59
87
  end
60
88
  end
61
89
  end
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "spec_helper"
2
5
 
3
6
  describe Vault::EncryptedModel do
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "spec_helper"
2
5
 
3
6
  describe Vault::Rails::Configurable do
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require "spec_helper"
2
5
 
3
6
  describe Vault::Rails do
@@ -1,3 +1,6 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: MPL-2.0
3
+
1
4
  require 'spec_helper'
2
5
 
3
6
  RSpec.describe Vault::Rails do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vault-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-02 00:00:00.000000000 Z
11
+ date: 2025-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.17'
33
+ version: '0.18'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.17'
40
+ version: '0.18'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +124,7 @@ dependencies:
124
124
  version: 1.3.6
125
125
  description: Official Vault plugin for Rails
126
126
  email:
127
- - sethvargo@gmail.com
127
+ - team-vault-devex@hashicorp.com
128
128
  executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
@@ -164,9 +164,12 @@ files:
164
164
  - spec/dummy/config/locales/en.yml
165
165
  - spec/dummy/config/routes.rb
166
166
  - spec/dummy/config/secrets.yml
167
+ - spec/dummy/db/development.sqlite3
167
168
  - spec/dummy/db/migrate/20150428220101_create_people.rb
168
169
  - spec/dummy/db/schema.rb
170
+ - spec/dummy/db/test.sqlite3
169
171
  - spec/dummy/lib/binary_serializer.rb
172
+ - spec/dummy/log/development.log
170
173
  - spec/dummy/public/404.html
171
174
  - spec/dummy/public/422.html
172
175
  - spec/dummy/public/500.html
@@ -183,7 +186,7 @@ homepage: https://github.com/hashicorp/vault-rails
183
186
  licenses:
184
187
  - MPL-2.0
185
188
  metadata: {}
186
- post_install_message:
189
+ post_install_message:
187
190
  rdoc_options: []
188
191
  require_paths:
189
192
  - lib
@@ -198,8 +201,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
201
  - !ruby/object:Gem::Version
199
202
  version: '0'
200
203
  requirements: []
201
- rubygems_version: 3.2.32
202
- signing_key:
204
+ rubygems_version: 3.5.21
205
+ signing_key:
203
206
  specification_version: 4
204
207
  summary: Official Vault plugin for Rails
205
208
  test_files:
@@ -229,9 +232,12 @@ test_files:
229
232
  - spec/dummy/config/routes.rb
230
233
  - spec/dummy/config/secrets.yml
231
234
  - spec/dummy/config.ru
235
+ - spec/dummy/db/development.sqlite3
232
236
  - spec/dummy/db/migrate/20150428220101_create_people.rb
233
237
  - spec/dummy/db/schema.rb
238
+ - spec/dummy/db/test.sqlite3
234
239
  - spec/dummy/lib/binary_serializer.rb
240
+ - spec/dummy/log/development.log
235
241
  - spec/dummy/public/404.html
236
242
  - spec/dummy/public/422.html
237
243
  - spec/dummy/public/500.html