Skip to content

Commit

Permalink
init branch
Browse files Browse the repository at this point in the history
  • Loading branch information
leonovk committed May 18, 2024
1 parent c31ad6d commit cfd059d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.1.1
v1.1.2
5 changes: 4 additions & 1 deletion app/errors/config_not_found_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
require_relative 'base_error'

module Errors
class ConfigNotFoundError < BaseError
class ConfigNotFoundError < BaseError # rubocop:disable Style/Documentation
def message
'The requested config was not found on the server'
end
end
end
8 changes: 6 additions & 2 deletions lib/wire_guard/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def initialize_data
end

def create_json_server_config # rubocop:disable Metrics/MethodLength
@json_config = {
json_config = {
server: {
private_key: @server_private_key,
public_key: @server_public_key,
Expand All @@ -90,7 +90,11 @@ def create_json_server_config # rubocop:disable Metrics/MethodLength
}
}

dump_json_config(@json_config)
dump_json_config(json_config)
# NOTE: Сreate their hash above a new Jason file
# and read the result and write it to an instant variable.
# So as not to turn all the keys into strings.
@json_config = JSON.parse(File.read(WG_JSON_PATH))
end

def dump_json_config(config)
Expand Down
34 changes: 30 additions & 4 deletions spec/app/clients_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@
end

describe '#create' do
before do
create_conf_file('spec/fixtures/empty_wg0.json')
end

let(:expected_result) do
{
id: 1,
Expand All @@ -172,9 +168,39 @@
}
end

let(:expected_config_file) do
{
server: {
private_key: 'wg_genkey',
public_key: 'wg_pubkey',
address: '10.8.0.1'
},
configs: {
last_id: 1,
last_address: '10.8.0.2',
'1' => {
id: 1,
address: '10.8.0.2',
private_key: 'wg_genkey',
public_key: 'wg_pubkey',
preshared_key: 'wg_genpsk',
data: nil
}
}
}
end

it 'return new config' do
expect(controller.create(nil)).to eq(expected_result.to_json)
end

it 'creates a new config file in the server configuration file' do
controller.create(nil)

json_config = File.read(wg_conf_path)

expect(json_config).to eq(JSON.pretty_generate(expected_config_file))
end
end

describe '#destroy' do
Expand Down

0 comments on commit cfd059d

Please sign in to comment.