Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added fields to migration & updated code for software file

  • Loading branch information...
commit 7edb2482caac0ac253d255ca5ce1f98888fb7cdc 1 parent 9c863eb
@rivanenko rivanenko authored
View
8 Rakefile
@@ -10,10 +10,4 @@ end
task :default => :spec
-task :build do
- system "gem build mobile_defense.gemspec"
-end
-
-task :install => :build do
- system "gem install pkg/mobile_defense-#{MobileDefense::VERSION}.gem"
-end
+# build, install tasks are inherited from Bundler::GemHelper
View
6 lib/generators/templates/migration.rb
@@ -13,6 +13,12 @@ def self.up
t.datetime :md_created_at
t.boolean :md_contains_encryption
t.integer :md_reference_id
+
+ t.integer :md_response_code
+ t.string :md_response_type
+ t.string :md_error_message
+ t.string :md_error
+
t.timestamps
end
View
5 lib/mobile_defense.rb
@@ -3,7 +3,7 @@
module MobileDefense
def self.version_string
- "MobileDefense version #{MobileDefense::VERSION}"
+ "MobileDefense version #{MobileDefense::MD_VERSION}"
end
ROOT = File.expand_path(File.dirname(__FILE__))
@@ -13,5 +13,4 @@ def self.version_string
autoload :ScanFile, "#{ROOT}/mobile_defense/scan_file"
end
-#ActiveRecord::Base.extend MobileDefense
-ActiveRecord::Base.class_eval { include MobileDefense::Scannable }
+ActiveRecord::Base.send(:include, MobileDefense::Scannable)
@jingweno
jingweno added a note

Is there a reason why all ActiveRecord::Base children have to know about MobileDefense::Scannable?

@jingweno
jingweno added a note

I would suggest to remove the line and if we use it then include it.

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
65 lib/mobile_defense/scannable.rb
@@ -8,16 +8,24 @@ def self.included(base)
module ClassMethods
def acts_as_scannable
- has_many :scan_responses, :as => :response_owner, :class_name => "::MobileDefense::ScanResponse", :dependent => :destroy
- has_many :scan_files, :as => :file_owner, :class_name => "::MobileDefense::ScanFile", :dependent => :destroy
+ if self.respond_to?(:software)
+ has_many :scan_responses, :as => :response_owner, :class_name => "::MobileDefense::ScanResponse", :dependent => :destroy
+ has_many :scan_files, :as => :file_owner, :class_name => "::MobileDefense::ScanFile", :dependent => :destroy
- include MobileDefense::Scannable::InstanceMethods
+ include MobileDefense::Scannable::InstanceMethods
+ end
end
end
module InstanceMethods
- def initiate_scan!(path_to_file = nil, options = {})
- path_to_scanned_file = path_to_file.present? ? path_to_file : File.join('@', File.expand_path('../../../spec/config/apk_files/1a8dbcc249885cc2ac324e47bb7145735c980525.apk', __FILE__) )
+ def initiate_scan!(options = {})
+ if Rails
+ path_to_file = self.software.path if self.respond_to?(:software)
+ else
+ path_to_file = File.expand_path('../../../spec/config/apk_files/1a8dbcc249885cc2ac324e47bb7145735c980525.apk', __FILE__)
+ end
+
+ path_to_scanned_file = File.join('@', path_to_file.to_s )
request_options = auth_signature
data = {"app[binary]" => path_to_scanned_file, "callback_url" => request_options[:callback_url]}
@@ -32,13 +40,16 @@ def initiate_scan!(path_to_file = nil, options = {})
resp = send_api_request("POST", "#{request_options[:host]}#{request_options[:path]}", headers, data)
- resp
+ handle_scan_response!(resp)
end
def handle_scan_response!(response = {})
app_params = response.delete("app")
if app_params
- app_params = Hash[app_params.map {|k, v| [k == "id" ? "md_#{k}" : "md_reference_#{k}", v] }]
+ app_params = Hash[app_params.map do |k, v|
+ key = k == "id" ? "md_reference_#{k}" : "md_#{k}"
+ [key, v] if MobileDefense::ScanResponse.column_names.include?(key)
+ end ].symbolize_keys
self.scan_responses.create(app_params)
end
@@ -58,10 +69,17 @@ def scan_status_for(id)
resp
end
- def send_request(path_to_file = nil, options = {})
+ #added to test API calls using Typhoeus
+ def send_request(options = {})
require 'typhoeus'
- path_to_scanned_file = path_to_file.present? ? path_to_file : File.join('@', File.expand_path('../../../spec/config/apk_files/7aa495c4415bf4fc3921384cae16cf6c42658644.apk', __FILE__) )
+ if Rails
+ path_to_file = self.software.path if self.respond_to?(:software)
+ else
+ path_to_file = File.expand_path('../../../spec/config/apk_files/1a8dbcc249885cc2ac324e47bb7145735c980525.apk', __FILE__)
+ end
+
+ path_to_scanned_file = File.join('@', path_to_file.to_s )
request_options = auth_signature
data = {"app[binary]" => path_to_scanned_file, "callback_url" => request_options[:callback_url]}
@@ -79,10 +97,21 @@ def send_request(path_to_file = nil, options = {})
resp.body
end
+ #added to test auth_signature
+ def test_auth_signature(method = "POST")
+ auth_signature(method)
+ end
+
private
def load_config
- YAML::load_file(File.expand_path('../../../spec/config/mobile_defense.yml', __FILE__))
+ if MOBILE_DEFENSE_CONFIG
+ MOBILE_DEFENSE_CONFIG
+ elsif Rails
+ YAML::load_file("#{Rails.root}/config/mobile_defense.yml")[Rails.env].symbolize_keys
+ else
+ YAML::load_file(File.expand_path('../../generators/templates/config.yml', __FILE__))['development'].symbolize_keys
+ end
end
def auth_signature(method = "POST")
@@ -91,16 +120,16 @@ def auth_signature(method = "POST")
result = {}
config = load_config
- result[:shared_secret] = config['shared_secret']
- result[:callback_url] = config['callback_url']
- result[:host] = config['request_host']
- result[:path] = config['request_path']
+ result[:shared_secret] = config[:shared_secret]
+ result[:callback_url] = config[:callback_url]
+ result[:host] = config[:request_host]
+ result[:path] = config[:request_path]
result[:timestamp] = DateTime.now.strftime("%Y-%m-%dT%H:%m:%SZ")
- result[:client_id] = config['client_id']
+ result[:client_id] = config[:client_id]
request_uri = "#{result[:host]}#{result[:path]}"
request_method = method
request_digest_string = "#{result[:shared_secret]}#{result[:timestamp]}#{request_uri}#{request_method}#{result[:client_id]}"
- result[:request_digest] = Digest::SHA2.new.update(request_digest_string)
+ result[:request_digest] = Digest::SHA2.new.update(request_digest_string).to_s
result
end
@@ -120,6 +149,4 @@ def send_api_request(method, url, headers = {}, data = {})
end
end
-end
-
-ActiveRecord::Base.send(:include, MobileDefense::Scannable)
+end
View
2  lib/mobile_defense/version.rb
@@ -1,3 +1,3 @@
module MobileDefense
- VERSION = "0.0.1"
+ MD_VERSION = "0.0.1"
end
View
6 mobile_defense.gemspec
@@ -1,10 +1,8 @@
-# -*- encoding: utf-8 -*-
-$:.push File.expand_path("../lib", __FILE__)
-require "mobile_defense/version"
+require "lib/mobile_defense/version"
Gem::Specification.new do |s|
s.name = "mobile_defense"
- s.version = MobileDefense::VERSION
+ s.version = MobileDefense::MD_VERSION
s.authors = ["Ruslan Ivanenko"]
s.email = ["ruslan.ivanenko.84@gmail.com"]
s.summary = %q{Rails 3 scanning extension}
View
5 spec/config/mobile_defense.yml
@@ -1,5 +0,0 @@
-shared_secret: 2b68d2371a08716a51d195b92adfe364e51dac43
-client_id: E975766762E78D0EF61A
-request_host: https://staging.mobiledefense.com
-request_path: /api/v1/apps
-callback_url: https://dev.twipler.com
View
2  spec/lib/mobile_defense_spec.rb
@@ -2,6 +2,6 @@
describe "mobile_defense" do
it "should have tests" do
- MobileDefense.version_string.should == "MobileDefense version #{MobileDefense::VERSION}"
+ MobileDefense.version_string.should == "MobileDefense version #{MobileDefense::MD_VERSION}"
end
end
View
2  spec/lib/scannable_model_spec.rb
@@ -59,8 +59,6 @@
end
it "should receive valid application attributes" do
- r = subject.send_request()
- puts r
resp = subject.stub(:initiate_scan!).with(@path_to_file).and_return(@resp)[]
resp["response_code"].should_not be(401)
resp["app"].should_not be(nil)
Please sign in to comment.
Something went wrong with that request. Please try again.