Sha256: 8aec1ffd227cf5e15f354a1fd45f8ec0bd116c4a593890818daf76414100f109

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module Headdesk
  module Checks
    #
    # Check the version of the Facebook SDK
    #
    # Facebook deprecates SDKs 2 years after they are released.
    #
    class FacebookSDK
      include Check::APK

      describe 'Facebook SDK version'
      def call
        skip_check unless: -> { apk.class?('com/facebook/FacebookSdk') }
        facebook_sdk = apk.find_class('com/facebook/FacebookSdk')

        # TODO: Parse https://developers.facebook.com/docs/android/change-log-4x
        #       and fail if > 2 years old, warn if < 3 months remaining
        get_sdk_version = facebook_sdk.method('getSdkVersion').code
        describe 'com.facebook.FacebookSdk contains getSdkVersion method'
        fail_check if: -> { !get_sdk_version }

        facebook_sdks = YAML.load_file(Headdesk::FACEBOOK_SDK_VERSIONS_YAML)
        major, minor, patch = get_sdk_version.match(/const-string v0, "(\d+)\.(\d+)\.(\d+)"/).captures.map(&:to_i)

        sdk_in_use = (facebook_sdks.select do |sdk|
          sdk[:major] == major && sdk[:minor] == minor && sdk[:patch] == patch
        end).first

        describe "Found Facebook SDK version #{sdk_in_use[:version]}"
        fail_check if: -> { !sdk_in_use }

        export facebook_sdk: sdk_in_use

        describe "Facebook SDK was released in the last 2 years (using #{sdk_in_use[:version]}, released #{sdk_in_use[:date]})"
        fail_check if: -> { sdk_in_use[:date] < (Date.today - (365 * 2)) }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
headdesk-0.3.0 lib/headdesk/checks/facebook.rb
headdesk-0.2.0 lib/headdesk/checks/facebook.rb
headdesk-0.1.0 lib/headdesk/checks/facebook.rb