-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👷 Refactoring and more tests (#2)
- Loading branch information
Showing
15 changed files
with
347 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.byebug_history | ||
etc | ||
.rspec_status | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.1.4 | ||
v0.1.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe ClientsController do | ||
subject(:controller) { described_class.new } | ||
|
||
let(:wg_conf_path) { "#{Settings.wg_path}/wg0.json" } | ||
|
||
before do | ||
allow(WireGuard::ConfigUpdater).to receive(:update) | ||
allow(WireGuard::KeyGenerator).to receive_messages(wg_genkey: 'wg_genkey', wg_pubkey: 'wg_pubkey', | ||
wg_genpsk: 'wg_genpsk') | ||
end | ||
|
||
after do | ||
FileUtils.rm_rf(wg_conf_path) | ||
end | ||
|
||
describe '#index' do | ||
context 'when there is no configuration file' do | ||
let(:expected_result) do | ||
{ | ||
server: { | ||
private_key: 'wg_genkey', | ||
public_key: 'wg_pubkey', | ||
address: '10.8.0.1' | ||
}, | ||
configs: { | ||
last_id: 0, | ||
last_address: '10.8.0.1' | ||
} | ||
} | ||
end | ||
|
||
it 'creates a configuration file and returns an empty array' do # rubocop:disable RSpec/MultipleExpectations | ||
result = controller.index | ||
|
||
expect(result).to eq([].to_json) | ||
|
||
config = File.read(wg_conf_path) | ||
|
||
expect(config).to eq(JSON.pretty_generate(expected_result)) | ||
end | ||
end | ||
|
||
context 'when there is already a configuration file without clients' do | ||
before do | ||
FileUtils.cp('spec/fixtures/empty_wg0.json', wg_conf_path) | ||
end | ||
|
||
it 'returns an empty array' do | ||
expect(controller.index).to eq([].to_json) | ||
end | ||
end | ||
|
||
context 'when there is already a configuration file with clients' do | ||
before do | ||
FileUtils.cp('spec/fixtures/wg0.json', wg_conf_path) | ||
end | ||
|
||
let(:expected_result) do | ||
[ | ||
{ | ||
id: 1, | ||
server_public_key: 'uygGKpQt7gOwrP+bqkiXytafHiM+XqFGc0jtZVJ5bnw=', | ||
address: '10.8.0.2/24', | ||
private_key: 'MJn6fwoyqG8S6wsrJzWrUow4leZuEM9O8s+G+kcXElU=', | ||
public_key: 'LiXk4UOfnScgf4UnkcYNcz4wWeqTOW1UrHKRVhZ1OXg=', | ||
preshared_key: '3UzAMA6mLIGjHOImShNb5tWlkwxsha8LZZP7dm49meQ=', | ||
allowed_ips: '0.0.0.0/0, ::/0', | ||
dns: '1.1.1.1', | ||
persistent_keepalive: 0, | ||
endpoint: '2.2.2.2:51820', | ||
data: { | ||
lol: 'kek' | ||
} | ||
}, | ||
{ | ||
id: 2, | ||
server_public_key: 'uygGKpQt7gOwrP+bqkiXytafHiM+XqFGc0jtZVJ5bnw=', | ||
address: '10.8.0.3/24', | ||
private_key: 'aN7ye98FKrmydwfA6tHgHE1PbiidWzUJ9cltnies8F4=', | ||
public_key: 'hvIyIW2o8JROVKuY2yYFdUn0oA+43aLuT8KCy0YbORE=', | ||
preshared_key: 'dVW/5kF8wnsx0zAwR4uPIa06btACxpQ/rHBL1B3qPnk=', | ||
allowed_ips: '0.0.0.0/0, ::/0', | ||
dns: '1.1.1.1', | ||
persistent_keepalive: 0, | ||
endpoint: '2.2.2.2:51820', | ||
data: { | ||
cheburek: 'hah' | ||
} | ||
}, | ||
{ | ||
id: 3, | ||
server_public_key: 'uygGKpQt7gOwrP+bqkiXytafHiM+XqFGc0jtZVJ5bnw=', | ||
address: '10.8.0.4/24', | ||
private_key: 'eF3Owsqd5MGAIXjmALGBi8ea8mkFUmAiyh80U3hVXn8=', | ||
public_key: 'bPKBg66uC1J2hlkE31Of5wnkg+IjowVXgoLcjcLn0js=', | ||
preshared_key: 'IyVg7fktkSBxJ0uK82j6nlI7Vmo0E53eBmYZ723/45E=', | ||
allowed_ips: '0.0.0.0/0, ::/0', | ||
dns: '1.1.1.1', | ||
persistent_keepalive: 0, | ||
endpoint: '2.2.2.2:51820', | ||
data: { | ||
key: 'value' | ||
} | ||
} | ||
] | ||
end | ||
|
||
it 'returns a serialized array with all clients' do | ||
expect(controller.index).to eq(expected_result.to_json) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.