Skip to content

Commit

Permalink
Added a malware sample file and call POST/GET/DELETE to verify the se…
Browse files Browse the repository at this point in the history
…rvice
  • Loading branch information
EC2 Default User committed Aug 3, 2017
1 parent da59c17 commit 6395ab0
Show file tree
Hide file tree
Showing 11 changed files with 645 additions and 6 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem 'rails', '~> 5.1.2'
gem 'mysql2'
gem 'redis'
gem 'redis-namespace'
gem 'addressable'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ GEM
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
arel (8.0.0)
ast (2.3.0)
builder (3.2.3)
Expand Down Expand Up @@ -80,6 +82,7 @@ GEM
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
public_suffix (2.0.5)
puma (3.9.1)
rack (2.0.3)
rack-test (0.6.3)
Expand Down Expand Up @@ -177,6 +180,7 @@ PLATFORMS
ruby

DEPENDENCIES
addressable
database_cleaner
factory_girl_rails (~> 4.0)
faker
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/concerns/exception_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ module ExceptionHandler
rescue_from ActiveRecord::RecordInvalid do |e|
json_response({ message: e.message }, :unprocessable_entity)
end

rescue_from ActionController::RoutingError do |e|
json_response({ message: e.message }, :unprocessable_entity)
end
end
end
5 changes: 5 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ErrorsController < ApplicationController
def routing
json_response({ message: "wrong request" }, :bad_request)
end
end
4 changes: 2 additions & 2 deletions app/controllers/urlinfos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def create_by_url
end

def delete_by_url
Urlinfo.new.destroy_urlinfo_from_database(params)
head :no_content
lookup_result =Urlinfo.new.destroy_urlinfo_from_database(params)
json_response(lookup_result, :ok)
end

private
Expand Down
9 changes: 7 additions & 2 deletions app/models/urlinfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def set_urlinfo_in_cache(url, malware)
cache[url] = malware
end

def del_urlinfo_from_cache(url, malware)
cache = get_cache_connection_by_url(url)
cache.del(url)
end

def find_urlinfo_in_storage(params)
param_url = generate_url_from_params(params)
cached_value = get_url_in_cache(param_url)
Expand Down Expand Up @@ -51,9 +56,9 @@ def destroy_urlinfo_from_database(params)
domain_name: params[:domain_name],
query_string: params[:query_string]
).destroy_all
set_urlinfo_in_cache(param_url, false)
del_urlinfo_from_cache(param_url, false)

{ url: param_url, data_source: 'cache', malware: false }
{ url: param_url, data_source: 'none', malware: false }
end

private
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
:domain_name => /[^\/]+/,
:query_string => /[^\/]+/
}

match '*a', :to => 'errors#routing', :via => [:get, :post, :delete]
end
Loading

0 comments on commit 6395ab0

Please sign in to comment.