smartvpn-http-hooks 1.0.7 → 1.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 452d36d90e1e0b42c1115a570b99d67a73aad680
4
- data.tar.gz: 3bac4bacc5059ac0045b4c73517eceaf0e0b9e1c
3
+ metadata.gz: eca1a1784ca0a4e66a794d3f0a92e64c8aff85d6
4
+ data.tar.gz: 45a1a65ccb3d4172ca450e19f21dd0bf50485f05
5
5
  SHA512:
6
- metadata.gz: e3d5f961cdea917deb8860d5e2132cafc713f36e8ff128fb25dbc0216fd4ae35059a452cfb0dfdcfda37bf22411487d03f2b31690be43981b426853a8a6e9b85
7
- data.tar.gz: a4cb8b5fd0f11ce8955eb0633742de163a437ec91bea0d542868936d07665d8ae0bc2615062040501a91e2489a7640d2553bf2a1f29312d83fe2f92d9e00474b
6
+ metadata.gz: b7f2f48d7cb72eeb27223d4541563fec09df50857e5bc7fa947a9df2e5ae564050b305c637d6fdb778ea2a3d3ce48ef2edec11382e197d13c3d49c509c2c451a
7
+ data.tar.gz: '0886876bd100b98ca3549fba05b93e79a6b884e4136e252d298526328a27a1f3af66709efabd977bbd44cef6ae1b9e8b01d7b1864be1b212634c4dc9bfd27f82'
data/.env ADDED
@@ -0,0 +1,3 @@
1
+ API_HOST=api.smartvpn.biz
2
+ API_INITIALIZATION_KEY=secret
3
+ HOSTNAME=test.smartvpn.biz
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ dist: xenial
2
+ language: ruby
3
+ sudo: true
4
+
5
+ rvm:
6
+ - 2.1.1
7
+ - 2.3.4
8
+ - 2.5.3
9
+ - 2.6.0
10
+
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: 2.1.1
14
+ - rvm: 2.5.3
15
+ - rvm: 2.6.0
16
+
17
+ script: bundle exec rspec
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+ gem 'syck'
5
+ gem 'pry'
6
+ gem 'dotenv'
data/Gemfile.lock CHANGED
@@ -7,21 +7,30 @@ GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  addressable (2.3.5)
10
+ coderay (1.1.2)
10
11
  crack (0.4.2)
11
12
  safe_yaml (~> 1.0.0)
12
- diff-lcs (1.2.5)
13
- metaclass (0.0.4)
14
- mocha (1.0.0)
15
- metaclass (~> 0.0.1)
16
- rspec (2.14.1)
17
- rspec-core (~> 2.14.0)
18
- rspec-expectations (~> 2.14.0)
19
- rspec-mocks (~> 2.14.0)
20
- rspec-core (2.14.8)
21
- rspec-expectations (2.14.5)
22
- diff-lcs (>= 1.1.3, < 2.0)
23
- rspec-mocks (2.14.6)
13
+ diff-lcs (1.3)
14
+ dotenv (2.6.0)
15
+ method_source (0.9.2)
16
+ pry (0.11.3)
17
+ coderay (~> 1.1.0)
18
+ method_source (~> 0.9.0)
19
+ rspec (3.8.0)
20
+ rspec-core (~> 3.8.0)
21
+ rspec-expectations (~> 3.8.0)
22
+ rspec-mocks (~> 3.8.0)
23
+ rspec-core (3.8.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-expectations (3.8.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-mocks (3.8.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-support (3.8.0)
24
32
  safe_yaml (1.0.1)
33
+ syck (1.4.0)
25
34
  webmock (1.17.4)
26
35
  addressable (>= 2.2.7)
27
36
  crack (>= 0.3.2)
@@ -30,9 +39,11 @@ PLATFORMS
30
39
  ruby
31
40
 
32
41
  DEPENDENCIES
33
- mocha
34
- rspec
42
+ dotenv
43
+ pry
44
+ rspec (>= 3.8)
35
45
  smartvpn-http-hooks!
46
+ syck
36
47
  webmock
37
48
 
38
49
  BUNDLED WITH
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
+ [![Build Status](https://travis-ci.org/Mehonoshin/smartvpn-http-hooks.svg?branch=master)](https://travis-ci.org/Mehonoshin/smartvpn-http-hooks)
2
+
1
3
  # smartvpn-http-hooks
2
4
 
5
+ <a href="https://imgbb.com/"><img src="https://image.ibb.co/gEVXM9/Screen-Shot-2018-10-14-at-18-34-17.png" alt="smartvpn-billing" border="0"></a>
6
+
3
7
  This ruby gem is wrapper for OpenVPN server daemon.
4
8
 
5
9
  The main purpose of this gem - is to interact with remote API, located at billing system.
@@ -1,9 +1,16 @@
1
1
  require File.expand_path('../billing', __FILE__)
2
2
 
3
3
  module Api
4
+ # This class executes an HTTP call to the API in billing,
5
+ # when the node is started for the first time.
6
+ # As a result of activation if receives an auth key,
7
+ # which is used for signing all subsequent API calls.
4
8
  class Activation < Billing
9
+ PKI_PATH = '/hooks/pki/keys'
5
10
 
6
11
  def activate
12
+ return if active_node?
13
+
7
14
  if activated_successfully?
8
15
  save_auth_key
9
16
  else
@@ -17,23 +24,50 @@ module Api
17
24
  success_api_call?
18
25
  end
19
26
 
27
+ def active_node?
28
+ File.exist?(KEY_PATH)
29
+ end
30
+
20
31
  def save_auth_key
21
32
  key = JSON.parse(api_call_result.body)["auth_key"]
22
33
  File.open('/etc/openvpn/auth_key', 'w') { |file| file.write(key) }
23
34
  end
24
35
 
25
36
  def signed_data
37
+ # TODO: sign initial request with secret key
26
38
  data
27
39
  end
28
40
 
29
41
  def data
30
42
  {
31
- hostname: hostname
43
+ # TODO: we should subscribe initial activation with secret key
44
+ # instead of relying on node IP
45
+ # secret_key: ENV['SECRET_KEY'],
46
+ hostname: hostname,
47
+ server_crt: server_crt,
48
+ client_crt: client_crt,
49
+ client_key: client_key
32
50
  }
33
51
  end
34
52
 
53
+ def server_crt
54
+ read_pki('ca.crt')
55
+ end
56
+
57
+ def client_crt
58
+ read_pki('generic_client.crt')
59
+ end
60
+
61
+ def client_key
62
+ read_pki('generic_client.key')
63
+ end
64
+
35
65
  def action
36
66
  "activate"
37
67
  end
68
+
69
+ def read_pki(file)
70
+ File.read("#{PKI_PATH}/#{file}")
71
+ end
38
72
  end
39
73
  end
data/lib/api/billing.rb CHANGED
@@ -5,11 +5,10 @@ require File.expand_path('../../signer', __FILE__)
5
5
 
6
6
  module Api
7
7
  class Billing
8
- API_HOST = '/etc/openvpn/API_HOST'
9
8
  KEY_PATH = '/etc/openvpn/auth_key'
10
9
 
11
10
  def host_with_port
12
- host = File.read(API_HOST)
11
+ host = ENV['API_HOST']
13
12
  "http://#{host.strip}"
14
13
  end
15
14
 
@@ -18,7 +17,7 @@ module Api
18
17
  end
19
18
 
20
19
  def hostname
21
- Socket.gethostname
20
+ ENV['HOSTNAME']
22
21
  end
23
22
 
24
23
  def success_api_call?
@@ -14,5 +14,4 @@ class OpenvpnPasswordAuthenticator
14
14
  exit 1
15
15
  end
16
16
  end
17
-
18
17
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'smartvpn-http-hooks'
3
- s.version = '1.0.7'
4
- s.date = '2019-01-08'
3
+ s.version = '1.0.8'
4
+ s.date = '2019-01-22'
5
5
  s.summary = "HTTP hooks for OpenVPN server"
6
6
  s.description = "Trigger on openvpn events and notify HTTP API"
7
7
  s.authors = ["Stanislav Mekhonoshin"]
@@ -11,7 +11,6 @@ Gem::Specification.new do |s|
11
11
  s.executables = ['smartvpn-activate', 'smartvpn-authenticate', 'smartvpn-connect', 'smartvpn-disconnect']
12
12
  s.license = 'MIT'
13
13
  s.require_path = 'lib'
14
- s.add_development_dependency 'rspec', ['>= 0']
15
- s.add_development_dependency 'mocha'
14
+ s.add_development_dependency 'rspec', ['>= 3.8']
16
15
  s.add_development_dependency 'webmock'
17
16
  end
@@ -4,13 +4,36 @@ describe Api::Activation do
4
4
  subject { described_class.new }
5
5
 
6
6
  describe '.activate' do
7
+ mock_pki_files
8
+
9
+ context 'when node is already activated' do
10
+ before do
11
+ expect(File)
12
+ .to receive(:exist?)
13
+ .with('/etc/openvpn/auth_key')
14
+ .and_return(true)
15
+ end
16
+
17
+ it 'does not make http calls' do
18
+ expect(subject).not_to receive(:activated_successfully?)
19
+ subject.activate
20
+ end
21
+ end
22
+
7
23
  context 'successful activation' do
8
24
  before do
9
25
  stub_request(:post, 'api.smartvpn.biz/api/activate')
26
+ .with(body: {
27
+ hostname: ENV['HOSTNAME'],
28
+ server_crt: 'crt content',
29
+ client_crt: 'client crt content',
30
+ client_key: 'client key content'
31
+ }
32
+ )
10
33
  end
11
34
 
12
35
  it 'saves key' do
13
- subject.expects(:save_auth_key)
36
+ allow(subject).to receive(:save_auth_key)
14
37
  subject.activate
15
38
  end
16
39
  end
@@ -23,7 +46,7 @@ describe Api::Activation do
23
46
  it 'raises error' do
24
47
  expect {
25
48
  subject.activate
26
- }.to raise_error
49
+ }.to raise_error "Can't activate server at billing"
27
50
  end
28
51
  end
29
52
  end
@@ -5,7 +5,7 @@ describe Api::Authentication do
5
5
 
6
6
  describe '.valid_credentials?' do
7
7
  before do
8
- subject.stubs(:auth_key).returns('key')
8
+ allow(subject).to receive(:auth_key).and_return('key')
9
9
  stub_request(:post, 'api.smartvpn.biz/api/auth').
10
10
  to_return(status: status)
11
11
  end
@@ -14,7 +14,7 @@ describe Api::Authentication do
14
14
  let(:status) { 200 }
15
15
 
16
16
  it 'returns true' do
17
- expect(subject.valid_credentials?).to be_true
17
+ expect(subject.valid_credentials?).to be true
18
18
  end
19
19
  end
20
20
 
@@ -22,7 +22,7 @@ describe Api::Authentication do
22
22
  let(:status) { 404 }
23
23
 
24
24
  it 'returns false' do
25
- expect(subject.valid_credentials?).to be_false
25
+ expect(subject.valid_credentials?).to be false
26
26
  end
27
27
  end
28
28
  end
@@ -3,33 +3,32 @@ require 'spec_helper'
3
3
  describe Api::Billing do
4
4
  subject { described_class.new }
5
5
 
6
- it "returns api url" do
7
- expect(subject.host_with_port).to include "http://"
6
+ it 'returns api url' do
7
+ expect(subject.host_with_port).to include 'http://'
8
8
  end
9
9
 
10
- it "reads file with auth key" do
11
- File.stubs(:read).with(described_class::KEY_PATH).returns("key")
12
- expect(subject.auth_key).to eq "key"
10
+ it 'reads file with auth key' do
11
+ allow(File).to receive(:read).with(described_class::KEY_PATH).and_return('key')
12
+ expect(subject.auth_key).to eq 'key'
13
13
  end
14
14
 
15
- it "returns machine hostname" do
16
- Socket.stubs(:gethostname).returns("hostname.dev")
17
- expect(subject.hostname).to eq "hostname.dev"
15
+ it 'returns machine hostname' do
16
+ expect(subject.hostname).to eq 'test.smartvpn.biz'
18
17
  end
19
18
 
20
- describe ".success_api_call?" do
21
- let(:api_call_result) { mock() }
19
+ describe '.success_api_call?' do
20
+ let(:api_call_result) { double() }
22
21
 
23
22
  before do
24
- api_call_result.stubs(:code).returns(code)
25
- subject.stubs(:api_call_result).returns(api_call_result)
23
+ allow(api_call_result).to receive(:code).and_return(code)
24
+ allow(subject).to receive(:api_call_result).and_return(api_call_result)
26
25
  end
27
26
 
28
27
  context "result is 404" do
29
28
  let(:code) { "404" }
30
29
 
31
30
  it "api call is not successful" do
32
- expect(subject.success_api_call?).to be_false
31
+ expect(subject.success_api_call?).to be false
33
32
  end
34
33
  end
35
34
 
@@ -37,7 +36,7 @@ describe Api::Billing do
37
36
  let(:code) { "200" }
38
37
 
39
38
  it "api call is successful" do
40
- expect(subject.success_api_call?).to be_true
39
+ expect(subject.success_api_call?).to be true
41
40
  end
42
41
  end
43
42
  end
@@ -48,24 +47,24 @@ describe Api::Billing do
48
47
  end
49
48
 
50
49
  it "fetches HTTP response" do
51
- subject.stubs(:action).returns("auth")
52
- subject.stubs(:data).returns({})
53
- subject.stubs(:auth_key).returns("key")
50
+ allow(subject).to receive(:action).and_return("auth")
51
+ allow(subject).to receive(:data).and_return({})
52
+ allow(subject).to receive(:auth_key).and_return("key")
54
53
 
55
54
  subject.api_call_result
56
- expect(subject.success_api_call?).to be_true
55
+ expect(subject.success_api_call?).to be true
57
56
  end
58
57
  end
59
58
 
60
59
  it "returns URI for api call" do
61
60
  action = "auth"
62
- subject.stubs(:action).returns(action)
63
- expect(subject.uri).to eq URI("http://#{described_class::API_HOST}/api/#{action}")
61
+ allow(subject).to receive(:action).and_return(action)
62
+ expect(subject.uri).to eq URI("#{subject.host_with_port}/api/#{action}")
64
63
  end
65
64
 
66
65
  it "adds signature to params hash" do
67
- subject.stubs(:auth_key).returns("key")
68
- subject.stubs(:data).returns({})
66
+ allow(subject).to receive(:auth_key).and_return("key")
67
+ allow(subject).to receive(:data).and_return({})
69
68
  expect(subject.signed_data).not_to be_empty
70
69
  end
71
70
  end
@@ -5,21 +5,23 @@ describe Api::Connect do
5
5
 
6
6
  describe '#invoke' do
7
7
  before do
8
- subject.stubs(:response).returns(
8
+ allow(subject).to receive(:response).and_return(
9
9
  JSON.parse(
10
10
  '{"id":101,"common_name":"login","options":["i2p", "proxy"],"option_attributes":{"i2p":{"attr1": "value1"},"proxy":{"attr2": "value2"}}}'
11
11
  )
12
12
  )
13
- subject.stubs(:trigger_script_return)
14
- subject.stubs(:success_api_call?).returns(api_call_validation_result)
13
+ allow(subject).to receive(:trigger_script_return)
14
+ allow(subject).to receive(:success_api_call?).and_return(api_call_validation_result)
15
15
  end
16
16
 
17
17
  context 'successfull script call' do
18
18
  let(:api_call_validation_result) { true }
19
19
 
20
20
  it 'activates options' do
21
- Option::I2p.any_instance.expects(:activate!)
22
- Option::Proxy.any_instance.expects(:activate!)
21
+ allow_any_instance_of(Option::I2p)
22
+ .to receive(:activate!)
23
+ allow_any_instance_of(Option::Proxy)
24
+ .to receive(:activate!)
23
25
  subject.invoke
24
26
  end
25
27
  end
@@ -28,7 +30,8 @@ describe Api::Connect do
28
30
  let(:api_call_validation_result) { false }
29
31
 
30
32
  it 'does not activate options' do
31
- Option::I2p.any_instance.expects(:activate!).never
33
+ allow_any_instance_of(Option::I2p)
34
+ .to receive(:activate!).never
32
35
  subject.invoke
33
36
  end
34
37
  end
@@ -5,8 +5,8 @@ describe Api::Connection do
5
5
 
6
6
  describe '.invoke_if_valid_api_call' do
7
7
  before do
8
- subject.stubs(:success_api_call?).returns(success_status)
9
- subject.expects(:exit).with(exit_status)
8
+ allow(subject).to receive(:success_api_call?).and_return(success_status)
9
+ expect(subject).to receive(:exit).with(exit_status)
10
10
  end
11
11
 
12
12
  context 'success' do
@@ -33,7 +33,7 @@ describe Api::Connection do
33
33
  let(:common_name) { "login" }
34
34
 
35
35
  before do
36
- subject.stubs(:response).returns(
36
+ allow(subject).to receive(:response).and_return(
37
37
  JSON.parse(
38
38
  "{\"id\":101,\"common_name\":\"#{common_name}\",\"options\":[\"#{option_name}\", \"proxy\"],\"option_attributes\":{\"i2p\":{\"attr1\": \"value1\"},\"proxy\":{\"attr2\": \"value2\"}}}"
39
39
  )
@@ -5,21 +5,21 @@ describe Api::Disconnect do
5
5
 
6
6
  describe '#invoke' do
7
7
  before do
8
- subject.stubs(:response).returns(
8
+ allow(subject).to receive(:response).and_return(
9
9
  JSON.parse(
10
10
  '{"id":101,"common_name":"login","options":["i2p", "proxy"],"option_attributes":{"i2p":{"attr1": "value1"},"proxy":{"attr2": "value2"}}}'
11
11
  )
12
12
  )
13
- subject.stubs(:trigger_script_return)
14
- subject.stubs(:success_api_call?).returns(api_call_validation_result)
13
+ allow(subject).to receive(:trigger_script_return)
14
+ allow(subject).to receive(:success_api_call?).and_return(api_call_validation_result)
15
15
  end
16
16
 
17
17
  context 'successfull script call' do
18
18
  let(:api_call_validation_result) { true }
19
19
 
20
- it 'activates options' do
21
- Option::I2p.any_instance.expects(:deactivate!)
22
- Option::Proxy.any_instance.expects(:deactivate!)
20
+ it 'deactivates options' do
21
+ allow_any_instance_of(Option::I2p).to receive(:deactivate!)
22
+ allow_any_instance_of(Option::Proxy).to receive(:deactivate!)
23
23
  subject.invoke
24
24
  end
25
25
  end
@@ -28,7 +28,7 @@ describe Api::Disconnect do
28
28
  let(:api_call_validation_result) { false }
29
29
 
30
30
  it 'does not activate options' do
31
- Option::I2p.any_instance.expects(:deactivate!).never
31
+ expect(Option::I2p).to receive(:deactivate!).never
32
32
  subject.invoke
33
33
  end
34
34
  end
@@ -16,26 +16,26 @@ describe OpenvpnPasswordAuthenticator do
16
16
 
17
17
  describe ".new" do
18
18
  it "read file with credentials" do
19
- File.expects(:read).with(path_to_file).returns(file_content)
19
+ expect(File).to receive(:read).with(path_to_file).and_return(file_content)
20
20
  subject
21
21
  end
22
22
 
23
23
  it "creates new adapter instance with credentials" do
24
- api_adapter_class.expects(:new).with('login', 'password')
24
+ expect(api_adapter_class).to receive(:new).with('login', 'password')
25
25
  subject
26
26
  end
27
27
  end
28
28
 
29
29
  describe ".authenticate" do
30
30
  before do
31
- subject.api.stubs(:valid_credentials?).returns(validation_result)
31
+ allow(subject.api).to receive(:valid_credentials?).and_return(validation_result)
32
32
  end
33
33
 
34
34
  context "credentials valid" do
35
35
  let(:validation_result) { true }
36
36
 
37
37
  it "exits with 0 code" do
38
- subject.expects(:exit).with(0)
38
+ expect(subject).to receive(:exit).with(0)
39
39
  subject.authenticate
40
40
  end
41
41
  end
@@ -44,7 +44,7 @@ describe OpenvpnPasswordAuthenticator do
44
44
  let(:validation_result) { false }
45
45
 
46
46
  it "exits with 1 code" do
47
- subject.expects(:exit).with(1)
47
+ expect(subject).to receive(:exit).with(1)
48
48
  subject.authenticate
49
49
  end
50
50
  end
@@ -7,20 +7,19 @@ describe Option::Base do
7
7
 
8
8
  describe 'activate' do
9
9
  it 'creates instance of class and calls activate! on it' do
10
- object = mock()
11
- object.expects(:activate!)
12
- subject.expects(:new).with(common_name, attributes).returns(object)
10
+ object = double()
11
+ expect(object).to receive(:activate!)
12
+ expect(subject).to receive(:new).with(common_name, attributes).and_return(object)
13
13
  subject.activate(common_name, attributes)
14
14
  end
15
15
  end
16
16
 
17
17
  describe 'deactivate' do
18
18
  it 'creates instance of class and calls deactivate! on it' do
19
- object = mock()
20
- object.expects(:deactivate!)
21
- subject.expects(:new).with(common_name, attributes).returns(object)
19
+ object = double()
20
+ expect(object).to receive(:deactivate!)
21
+ expect(subject).to receive(:new).with(common_name, attributes).and_return(object)
22
22
  subject.deactivate(common_name, attributes)
23
23
  end
24
24
  end
25
-
26
25
  end
@@ -5,14 +5,14 @@ describe Option::I2p do
5
5
 
6
6
  describe '.activate' do
7
7
  it 'adds firewall rules' do
8
- subject.expects(:add_firewall_routes)
8
+ expect(subject).to receive(:add_firewall_routes)
9
9
  subject.activate!
10
10
  end
11
11
  end
12
12
 
13
13
  describe '.deactivate' do
14
14
  it 'removes firewall rules' do
15
- subject.expects(:remove_firewall_routes)
15
+ expect(subject).to receive(:remove_firewall_routes)
16
16
  subject.deactivate!
17
17
  end
18
18
  end
@@ -11,8 +11,8 @@ describe Option::Proxy do
11
11
  end
12
12
 
13
13
  it 'it starts proxy daemon and firewall rules' do
14
- subject.expects(:start_proxy_daemon).returns(9090)
15
- subject.expects(:add_firewall_rules).with(9090)
14
+ expect(subject).to receive(:start_proxy_daemon).and_return(9090)
15
+ expect(subject).to receive(:add_firewall_rules).with(9090)
16
16
  subject.activate!
17
17
  end
18
18
  end
@@ -23,9 +23,12 @@ describe Option::Proxy do
23
23
  end
24
24
 
25
25
  it 'stops daemon, removes firewall rule and cleans relays list' do
26
- Option::Proxy::RelayManager.any_instance.stubs(:free).with(anything).returns(9090)
27
- subject.expects(:remove_firewall_rules).with(9090)
28
- subject.expects(:kill_proxy_daemon).with(9090)
26
+ allow_any_instance_of(Option::Proxy::RelayManager)
27
+ .to receive(:free)
28
+ .with(anything)
29
+ .and_return(9090)
30
+ expect(subject).to receive(:remove_firewall_rules).with(9090)
31
+ expect(subject).to receive(:kill_proxy_daemon).with(9090)
29
32
  subject.deactivate!
30
33
  end
31
34
  end
@@ -5,7 +5,7 @@ describe System::OpenvpnStatusLogParser do
5
5
  subject { described_class }
6
6
 
7
7
  it 'calls parse method' do
8
- subject.any_instance.expects(:parse)
8
+ expect_any_instance_of(subject).to receive(:parse)
9
9
  subject.new("")
10
10
  end
11
11
  end
@@ -5,15 +5,15 @@ describe System::OpenvpnStatusLogReader do
5
5
  let(:common_name) { "e0c187715fa9e1bb9fd96882dfa7af22" }
6
6
  let(:path_to_log) { described_class::LOGFILE_PATH }
7
7
 
8
- before { File.stubs(:read).with(path_to_log).returns(file_contents) }
8
+ before { allow(File).to receive(:read).with(path_to_log).and_return(file_contents) }
9
9
 
10
10
  describe '.vpn_ip' do
11
11
  subject { described_class }
12
12
 
13
13
  it 'creates new instance and vpn_ip_for on it' do
14
- object = mock()
15
- object.expects(:vpn_ip_for).with(common_name)
16
- subject.expects(:new).returns(object)
14
+ object = double()
15
+ expect(object).to receive(:vpn_ip_for).with(common_name)
16
+ expect(subject).to receive(:new).and_return(object)
17
17
  subject.vpn_ip(common_name)
18
18
  end
19
19
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,13 @@
1
- require 'rspec/autorun'
1
+ require 'rubygems' unless defined?(Gem)
2
+ require 'bundler/setup'
3
+ Bundler.require(:default)
4
+
5
+ require 'dotenv/load'
2
6
  require 'webmock/rspec'
3
7
  require 'smartvpn-http-hooks'
8
+ require 'support/mocks'
4
9
 
5
10
  RSpec.configure do |config|
6
- config.mock_with :mocha
11
+ config.mock_with :rspec
12
+ config.extend Smartvpn::Mocks
7
13
  end
8
-
9
-
@@ -0,0 +1,22 @@
1
+ module Smartvpn
2
+ module Mocks
3
+ def mock_pki_files
4
+ before do
5
+ allow(File)
6
+ .to receive(:read)
7
+ .with('/hooks/pki/keys/ca.crt')
8
+ .and_return('crt content')
9
+
10
+ allow(File)
11
+ .to receive(:read)
12
+ .with('/hooks/pki/keys/generic_client.crt')
13
+ .and_return('client crt content')
14
+
15
+ allow(File)
16
+ .to receive(:read)
17
+ .with('/hooks/pki/keys/generic_client.key')
18
+ .and_return('client key content')
19
+ end
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartvpn-http-hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav Mekhonoshin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-08 00:00:00.000000000 Z
11
+ date: 2019-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.8'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: mocha
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '3.8'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: webmock
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -62,8 +48,10 @@ executables:
62
48
  extensions: []
63
49
  extra_rdoc_files: []
64
50
  files:
51
+ - ".env"
65
52
  - ".gitignore"
66
53
  - ".rspec"
54
+ - ".travis.yml"
67
55
  - Gemfile
68
56
  - Gemfile.lock
69
57
  - LICENSE
@@ -108,6 +96,7 @@ files:
108
96
  - spec/lib/system/openvpn_status_log_reader_spec.rb
109
97
  - spec/lib/system/openvpn_status_spec.rb
110
98
  - spec/spec_helper.rb
99
+ - spec/support/mocks.rb
111
100
  homepage: https://github.com/Mehonoshin/smartvpn-http-hooks
112
101
  licenses:
113
102
  - MIT