tcr 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fefcbc3629fb40e1de900a369921440783e9640b
4
- data.tar.gz: ff7b6ab916e2c94f44036b5d984606d3acac0941
3
+ metadata.gz: d304ca968d1155919b181710a474dd9a98a4f269
4
+ data.tar.gz: 67e7387321ce706d2b7dc1651bcbdc825ae682d1
5
5
  SHA512:
6
- metadata.gz: 0848a1a7a8fb7088db93e61e5f0fda53a391768773a7dc8591b35ceb2e71270aa17d8347997b0594ca61eaf234600c26cf58d8274a971d6c18b54b03e9d7e4d4
7
- data.tar.gz: 835f96abc00e39d5dff708d51a654a7f736826ffc265a3ec35ecfe27a82ef18681ee578e901a243978a4165b17c54b4beab674ffa3dd2a506bb63fbeb00d3436
6
+ metadata.gz: 051e136095dcd34c387d7638124bd453b6ba7134ea06bf784e1501fb04fe2c7d1f1ed11bd64a3edae17dd9bcea54f241be985901bf958cf1652aa129df9bffae
7
+ data.tar.gz: e9ffe3fc3379731f11a78ed2fb017480a8372d1ff2563019df12f704e9780e61c8ef5392ebe0057cb91b05940c7b5d7d820f492a161fd351d12ad541b1f652ae
data/.travis.yml CHANGED
@@ -1,10 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.9.3"
4
3
  - "2.0.0"
5
- - "2.1.2"
6
- - "2.2.2"
7
- - "2.3.1"
4
+ - "2.1.10"
5
+ - "2.2.10"
6
+ - "2.3.7"
7
+ - "2.4.4"
8
+ - "2.5.1"
8
9
  before_install:
9
10
  - gem install bundler
10
11
  script: bundle exec rspec
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  TCR is a *very* lightweight version of [VCR](https://github.com/vcr/vcr) for TCP sockets.
8
8
 
9
- Currently used for recording 'net/smtp' interactions so only a few of the TCPSocket methods are recorded out.
9
+ Currently used for recording 'net/smtp', 'net/imap' and 'net/ldap' interactions so only a few of the TCPSocket methods are recorded out.
10
10
 
11
11
  ## Installation
12
12
 
@@ -87,6 +87,26 @@ TCR.configure do |c|
87
87
  c.hit_all = true
88
88
  end
89
89
  ```
90
+
91
+ The following storage formats are supported:
92
+
93
+ - JSON (default)
94
+ - YAML
95
+ - Marshal (recommended for binary data transfer like LDAP)
96
+
97
+ You can configure them via:
98
+
99
+ ```ruby
100
+ TCR.configure do |c|
101
+ c.format = 'json'
102
+ # or
103
+ c.format = 'yaml'
104
+ # or
105
+ c.format = 'marshal'
106
+ end
107
+ ```
108
+
109
+
90
110
  ## Contributing
91
111
 
92
112
  1. Fork it
data/lib/tcr/cassette.rb CHANGED
@@ -49,6 +49,8 @@ module TCR
49
49
  JSON.parse(content)
50
50
  when "yaml"
51
51
  YAML.load(content)
52
+ when "marshal"
53
+ Marshal.load(content)
52
54
  else
53
55
  raise RuntimeError.new "unrecognized format #{TCR.configuration.format}, please use `json` or `yaml`"
54
56
  end
@@ -60,6 +62,8 @@ module TCR
60
62
  JSON.pretty_generate(content)
61
63
  when "yaml"
62
64
  YAML.dump(content)
65
+ when "marshal"
66
+ Marshal.dump(content)
63
67
  else
64
68
  raise RuntimeError.new "unrecognized format #{TCR.configuration.format}, please use `json` or `yaml`"
65
69
  end
@@ -0,0 +1,19 @@
1
+ # support LDAP(S) connections
2
+ if defined? ::Net::LDAP
3
+
4
+ module Net::LDAP::Connection::FixSSLSocketSyncClose
5
+ def close
6
+ super
7
+ # see: https://github.com/ruby-ldap/ruby-net-ldap/pull/314
8
+ return if io.closed?
9
+ io.close
10
+ end
11
+ end
12
+
13
+ module TCR
14
+ class RecordableTCPSocket
15
+ include Net::LDAP::Connection::GetbyteForSSLSocket
16
+ include Net::BER::BERParser
17
+ end
18
+ end
19
+ end
@@ -17,7 +17,8 @@ module TCR
17
17
  @live = true
18
18
  @socket = TCPSocket.real_open(address, port)
19
19
  else
20
- @live = false
20
+ @live = false
21
+ @closed = false
21
22
  end
22
23
  @recording = cassette.next_session
23
24
  end
@@ -26,6 +27,10 @@ module TCR
26
27
  _read(:read, bytes)
27
28
  end
28
29
 
30
+ def getc(*args)
31
+ _read(:getc, *args)
32
+ end
33
+
29
34
  def gets(*args)
30
35
  _read(:gets, *args)
31
36
  end
@@ -53,13 +58,15 @@ module TCR
53
58
  if live
54
59
  @socket.closed?
55
60
  else
56
- false
61
+ @closed
57
62
  end
58
63
  end
59
64
 
60
65
  def close
61
66
  if live
62
67
  @socket.close
68
+ else
69
+ @closed = true
63
70
  end
64
71
  end
65
72
 
@@ -86,8 +93,9 @@ module TCR
86
93
 
87
94
  def _write(method, data)
88
95
  if live
89
- @socket.__send__(method, data)
90
- recording << ["write", data.dup.to_s.force_encoding("UTF-8")]
96
+ payload = data.dup if !data.is_a?(Symbol)
97
+ @socket.__send__(method, payload)
98
+ recording << ["write", data.dup]
91
99
  else
92
100
  direction, data = recording.shift
93
101
  _ensure_direction("write", direction)
@@ -102,8 +110,9 @@ module TCR
102
110
  end
103
111
 
104
112
  if live
105
- data = @socket.__send__(method, *args)
106
- recording << ["read", data.to_s.force_encoding("UTF-8")]
113
+ data = @socket.__send__(method, *args)
114
+ payload = data.dup if !data.is_a?(Symbol)
115
+ recording << ["read", payload]
107
116
  else
108
117
  _block_for_read_data if blocking && TCR.configuration.block_for_reads
109
118
  raise EOFError if recording.empty?
data/lib/tcr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TCR
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
Binary file
data/spec/tcr_spec.rb CHANGED
@@ -4,6 +4,8 @@ require "net/protocol"
4
4
  require "net/http"
5
5
  require "net/imap"
6
6
  require "net/smtp"
7
+ require "net/ldap"
8
+ require "tcr/net/ldap"
7
9
  require 'thread'
8
10
  require "mail"
9
11
 
@@ -16,9 +18,11 @@ describe TCR do
16
18
  around(:each) do |example|
17
19
  File.unlink("test.json") if File.exists?("test.json")
18
20
  File.unlink("test.yaml") if File.exists?("test.yaml")
21
+ File.unlink("test.marshal") if File.exists?("test.marshal")
19
22
  example.run
20
23
  File.unlink("test.json") if File.exists?("test.json")
21
24
  File.unlink("test.yaml") if File.exists?("test.yaml")
25
+ File.unlink("test.marshal") if File.exists?("test.marshal")
22
26
  end
23
27
 
24
28
  describe ".configuration" do
@@ -179,6 +183,16 @@ describe TCR do
179
183
  }.to change{ File.exists?("./test.yaml") }.from(false).to(true)
180
184
  end
181
185
 
186
+ it "creates a cassette file on use with marshal" do
187
+ TCR.configure { |c| c.format = "marshal" }
188
+
189
+ expect {
190
+ TCR.use_cassette("test") do
191
+ tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
192
+ end
193
+ }.to change{ File.exists?("./test.marshal") }.from(false).to(true)
194
+ end
195
+
182
196
  it "records the tcp session data into the file" do
183
197
  TCR.use_cassette("test") do
184
198
  tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
@@ -376,4 +390,31 @@ describe TCR do
376
390
  sock.print("hello\n".freeze)
377
391
  end
378
392
  end
393
+
394
+ it "supports Net::LDAP connections" do
395
+ TCR.configure { |c|
396
+ c.hook_tcp_ports = [389]
397
+ c.format = 'marshal'
398
+ c.cassette_library_dir = "."
399
+ }
400
+ expect {
401
+ TCR.use_cassette("spec/fixtures/ldap") do
402
+ ldap = Net::LDAP.new(
403
+ host: 'ldap.forumsys.com',
404
+ port: 389,
405
+ )
406
+
407
+ ldap.auth 'cn=read-only-admin,dc=example,dc=com', 'password'
408
+
409
+ ldap.search(
410
+ base: 'DC=example,DC=com',
411
+ filter: '(ou=mathematicians,dc=example,dc=com)',
412
+ scope: Net::LDAP::SearchScope_WholeSubtree,
413
+ return_result: false
414
+ ) do |_entry|
415
+ break
416
+ end
417
+ end
418
+ }.not_to raise_error
419
+ end
379
420
  end
data/tcr.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_development_dependency "rspec"
21
21
  gem.add_development_dependency "mail"
22
+ gem.add_development_dependency "net-ldap"
22
23
  gem.add_development_dependency "mime-types", "~>2.0"
23
24
  gem.add_development_dependency "geminabox"
24
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Forman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-16 00:00:00.000000000 Z
11
+ date: 2018-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-ldap
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: mime-types
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -84,12 +98,14 @@ files:
84
98
  - lib/tcr/cassette.rb
85
99
  - lib/tcr/configuration.rb
86
100
  - lib/tcr/errors.rb
101
+ - lib/tcr/net/ldap.rb
87
102
  - lib/tcr/recordable_tcp_socket.rb
88
103
  - lib/tcr/version.rb
89
104
  - spec/fixtures/block_for_reads.json
90
105
  - spec/fixtures/email_with_image.eml
91
106
  - spec/fixtures/google_https.json
92
107
  - spec/fixtures/google_imap.json
108
+ - spec/fixtures/ldap.marshal
93
109
  - spec/fixtures/mandrill_smtp.json
94
110
  - spec/fixtures/multitest-extra-smtp.json
95
111
  - spec/fixtures/multitest-smtp.json
@@ -127,6 +143,7 @@ test_files:
127
143
  - spec/fixtures/email_with_image.eml
128
144
  - spec/fixtures/google_https.json
129
145
  - spec/fixtures/google_imap.json
146
+ - spec/fixtures/ldap.marshal
130
147
  - spec/fixtures/mandrill_smtp.json
131
148
  - spec/fixtures/multitest-extra-smtp.json
132
149
  - spec/fixtures/multitest-smtp.json