-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a53d189
commit 85c9468
Showing
24 changed files
with
801 additions
and
224 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
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
2 changes: 1 addition & 1 deletion
2
...s_registry/domain_availability_checker.rb → ...ry/domain_availability_checker_service.rb
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 was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
test/integration/api/business_registry/domain_names_controller_test.rb
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,47 @@ | ||
require 'test_helper' | ||
|
||
class Api::V1::BusinessRegistry::DomainNamesControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@allowed_origins = ['http://example.com', 'https://test.com'] | ||
ENV['ALLOWED_ORIGINS'] = @allowed_origins.join(',') | ||
@valid_ip = '127.0.0.1' | ||
ENV['auction_api_allowed_ips'] = @valid_ip | ||
end | ||
|
||
test "should return list of available organization domain names" do | ||
get api_v1_business_registry_domain_names_path(organization_name: "Test Company AS"), | ||
headers: { 'Origin' => @allowed_origins.first, 'REMOTE_ADDR' => @valid_ip } | ||
|
||
assert_response :success | ||
assert_equal @allowed_origins.first, response.headers['Access-Control-Allow-Origin'] | ||
json_response = JSON.parse(response.body) | ||
assert_includes json_response['variants'], 'testcompany' | ||
assert_includes json_response['variants'], 'test-company' | ||
assert_includes json_response['variants'], 'test_company' | ||
assert_includes json_response['variants'], "testcompany#{Time.current.year}" | ||
end | ||
|
||
test "should handle invalid organization name" do | ||
get api_v1_business_registry_domain_names_path(organization_name: "Invalid!@#Name"), | ||
headers: { 'Origin' => @allowed_origins.first, 'REMOTE_ADDR' => @valid_ip } | ||
|
||
assert_response :bad_request | ||
json_response = JSON.parse(response.body) | ||
assert_equal 'Invalid organization name', json_response['error'] | ||
end | ||
|
||
test "should not set CORS header for disallowed origin" do | ||
get api_v1_business_registry_domain_names_path(organization_name: "Test Company"), | ||
headers: { 'Origin' => 'http://malicious.com', 'REMOTE_ADDR' => @valid_ip } | ||
|
||
assert_response :unauthorized | ||
assert_nil response.headers['Access-Control-Allow-Origin'] | ||
end | ||
|
||
test "should not allow access from unauthorized IP" do | ||
get api_v1_business_registry_domain_names_path(organization_name: "Test Company"), | ||
headers: { 'Origin' => @allowed_origins.first, 'REMOTE_ADDR' => '192.168.1.1' } | ||
|
||
assert_response :unauthorized | ||
end | ||
end |
67 changes: 67 additions & 0 deletions
67
test/integration/api/business_registry/refresh_token_controller_test.rb
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,67 @@ | ||
require 'test_helper' | ||
|
||
class Api::V1::BusinessRegistry::RefreshTokenControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@reserved_domain = reserved_domains(:one) | ||
@reserved_domain_status = ReservedDomainStatus.create( | ||
reserved_domain: @reserved_domain, | ||
name: @reserved_domain.name, | ||
token_created_at: Time.current | ||
) | ||
@reserved_domain_status.refresh_token | ||
@allowed_origins = ['http://example.com', 'https://test.com'] | ||
ENV['ALLOWED_ORIGINS'] = @allowed_origins.join(',') | ||
|
||
@valid_ip = '127.0.0.1' | ||
@invalid_ip = '192.168.1.1' | ||
ENV['auction_api_allowed_ips'] = @valid_ip | ||
end | ||
|
||
test "should refresh token" do | ||
old_token = @reserved_domain_status.access_token | ||
patch api_v1_business_registry_refresh_token_path, | ||
headers: { | ||
'Authorization' => "Bearer #{old_token}", | ||
'Origin' => @allowed_origins.first, | ||
'REMOTE_ADDR' => @valid_ip | ||
} | ||
assert_response :success | ||
assert_equal @allowed_origins.first, response.headers['Access-Control-Allow-Origin'] | ||
json_response = JSON.parse(response.body) | ||
assert_equal "Token refreshed", json_response['message'] | ||
assert_not_equal old_token, json_response['token'] | ||
end | ||
|
||
test "should return error for invalid token" do | ||
patch api_v1_business_registry_refresh_token_path, | ||
headers: { | ||
'Authorization' => "Bearer invalid_token", | ||
'Origin' => @allowed_origins.first, | ||
'REMOTE_ADDR' => @valid_ip | ||
} | ||
assert_response :unauthorized | ||
json_response = JSON.parse(response.body) | ||
assert_equal "Invalid token", json_response['error'] | ||
end | ||
|
||
test "should not set CORS header for disallowed origin" do | ||
patch api_v1_business_registry_refresh_token_path, | ||
headers: { | ||
'Authorization' => "Bearer #{@reserved_domain_status.access_token}", | ||
'Origin' => 'http://malicious.com', | ||
'REMOTE_ADDR' => @valid_ip | ||
} | ||
assert_response :unauthorized | ||
assert_nil response.headers['Access-Control-Allow-Origin'] | ||
end | ||
|
||
test "should not allow refresh from unauthorized IP" do | ||
patch api_v1_business_registry_refresh_token_path, | ||
headers: { | ||
'Authorization' => "Bearer #{@reserved_domain_status.access_token}", | ||
'Origin' => @allowed_origins.first, | ||
'REMOTE_ADDR' => @invalid_ip | ||
} | ||
assert_response :unauthorized | ||
end | ||
end |
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
Oops, something went wrong.