browser_sniffer 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd1a593002b74a298902288af9c9ad850599246545788da8ec5282661ace4b72
4
- data.tar.gz: e51a161b66ef5e9f237e498fed82c101ee55dcfd85493a2003743cdbf305be43
3
+ metadata.gz: 7466e6d392be9a8f030ff7301bfae8aa97ff0f44ebe0e31a7f662b8ddd1c45a5
4
+ data.tar.gz: 22a24aa5b13e3c663416a4cb015e03c3af315193cdd398945541e18829174df1
5
5
  SHA512:
6
- metadata.gz: dcce3cb34e52ffe1d43b5ee06f96d7093effce03cef846c709d7addc06555266edcd2f1b0d5b0879d5a5bae17e2f46d78cc64a939bc45e5a229f9575106f9011
7
- data.tar.gz: 4a2b2a8995d1e2b7cc6c9aa61bcbb839f63dae0963cd7513eb2ad88fae1755dc39713c730d8d74b0e51ec7a1257f5e4e87fde5a8bed88c87c9837e69f969c6fc
6
+ metadata.gz: 0f5a4612854ada3f81857d40d536817cb1064aec4dc6f24251d25658923dd91d45230091019defe14c594422004bd053402792a4b312d8fca5a5056b80a71479
7
+ data.tar.gz: 25b99d22d52f3e8dae0a9aeb345408121dd23076f4a3736dbd147ab398dd5b3490b7b09de7fb8e413664e4170d551c3683e4dc667e7e02d240cb2fd601501730
data/.travis.yml CHANGED
@@ -3,6 +3,10 @@ rvm:
3
3
  - 1.9
4
4
  - 2.0
5
5
  - 2.1
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
9
+ - truffleruby-19.2.0.1 # like 2.6.2
6
10
  - jruby
7
11
 
8
12
  before_install: gem update bundler
@@ -153,4 +153,42 @@ class BrowserSniffer
153
153
  end
154
154
  result
155
155
  end
156
+
157
+ def same_site_none_compatible?
158
+ return false unless user_agent
159
+
160
+ webkit_same_site_compatible? && same_site_recognized_browser?
161
+ end
162
+
163
+ def webkit_same_site_compatible?
164
+ return false unless os && os_version && browser
165
+
166
+ !(os == :ios && os_version.match(/^([0-9]|1[12])[\.\_]/)) &&
167
+ !(os == :mac && browser == :safari && os_version.match(/^10[\.\_]14/))
168
+ end
169
+
170
+ def same_site_recognized_browser?
171
+ return false unless major_browser_version
172
+
173
+ !(chromium_based? && major_browser_version >= 51 && major_browser_version <= 66) &&
174
+ !(uc_browser? && !uc_browser_version_at_least?(12, 13, 2))
175
+ end
176
+
177
+ def chromium_based?
178
+ browser_name ? browser_name.downcase.match(/chrom(e|ium)/) : false
179
+ end
180
+
181
+ def uc_browser?
182
+ user_agent ? user_agent.downcase.match(/uc\s?browser/) : false
183
+ end
184
+
185
+ def uc_browser_version_at_least?(major, minor, build)
186
+ return false unless browser_version
187
+ digits = browser_version.split('.').map(&:to_i)
188
+ return false unless digits.count >= 3
189
+
190
+ return digits[0] > major if digits[0] != major
191
+ return digits[1] > minor if digits[1] != minor
192
+ digits[2] >= build
193
+ end
156
194
  end
@@ -1,3 +1,3 @@
1
1
  class BrowserSniffer
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -406,6 +406,77 @@ describe "Shopify agents" do
406
406
  }), sniffer.os_info
407
407
  end
408
408
 
409
+ it "Shopify POS via webview can be sniffed" do
410
+ user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) "\
411
+ "AppleWebKit/ 604.1.21 (KHTML, like Gecko) Version/ 12.0 Mobile/17A6278a Safari/602.1.26 "\
412
+ "MobileMiddlewareSupported com.jadedpixel.pos Shopify POS/5.43.1 (iPad; iOS 13.1; Scale/2.00)"
413
+ sniffer = BrowserSniffer.new(user_agent)
414
+
415
+ assert_equal ({
416
+ name: 'Shopify POS',
417
+ version: '5.43.1',
418
+ }), sniffer.browser_info
419
+
420
+ assert_equal ({
421
+ type: :tablet,
422
+ scale: '2.00',
423
+ }), sniffer.device_info
424
+
425
+ assert_equal ({
426
+ type: :ios,
427
+ version: '13.1',
428
+ name: 'iOS',
429
+ }), sniffer.os_info
430
+ end
431
+
432
+ it "Shopify POS with modern user agent via webview can be sniffed" do
433
+ user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) "\
434
+ "AppleWebKit/ 604.1.21 (KHTML, like Gecko) Version/ 12.0 Mobile/17A6278a "\
435
+ "Safari/602.1.26 MobileMiddlewareSupported Shopify POS/iOS/3.12.1 "\
436
+ "(iPad4,7/com.jadedpixel.pos/10.3.1) - Build 1"
437
+ sniffer = BrowserSniffer.new(user_agent)
438
+
439
+ assert_equal ({
440
+ name: 'Shopify POS',
441
+ version: '3.12.1',
442
+ }), sniffer.browser_info
443
+
444
+ assert_equal ({
445
+ type: :tablet,
446
+ model: '4,7',
447
+ }), sniffer.device_info
448
+
449
+ assert_equal ({
450
+ type: :ios,
451
+ name: 'iOS',
452
+ version: '10.3.1',
453
+ }), sniffer.os_info
454
+ end
455
+
456
+ it "Shopify POS Next with modern user agent via webview can be sniffed" do
457
+ user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) "\
458
+ "AppleWebKit/ 604.1.21 (KHTML, like Gecko) Version/ 12.0 Mobile/17A6278a "\
459
+ "Safari/602.1.26 MobileMiddlewareSupported Shopify POS Next/iOS/3.12.1 "\
460
+ "(iPad4,7/com.jadedpixel.pos/10.3.1) - Build 1"
461
+ sniffer = BrowserSniffer.new(user_agent)
462
+
463
+ assert_equal ({
464
+ name: 'Shopify POS',
465
+ version: '3.12.1',
466
+ }), sniffer.browser_info
467
+
468
+ assert_equal ({
469
+ type: :tablet,
470
+ model: '4,7',
471
+ }), sniffer.device_info
472
+
473
+ assert_equal ({
474
+ type: :ios,
475
+ name: 'iOS',
476
+ version: '10.3.1',
477
+ }), sniffer.os_info
478
+ end
479
+
409
480
  it "Shopify POS with okhttp user agent can be parsed" do
410
481
  user_agent = "okhttp/3.6.0"
411
482
  sniffer = BrowserSniffer.new(user_agent)
@@ -603,4 +674,37 @@ describe "Shopify agents" do
603
674
  name: 'iOS',
604
675
  }), sniffer.os_info
605
676
  end
677
+
678
+ INCOMPATIBLE_USER_AGENTS = [
679
+ "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko)"\
680
+ " GSA/87.0.279142407 Mobile/15E148 Safari/605.1",
681
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko)"\
682
+ " Version/12.1.2 Safari/605.1.15",
683
+ "Mozilla/5.0 (Linux; U; Android 7.0; en-US; SM-G935F Build/NRD90M) AppleWebKit/534.30 (KHTML, like Gecko) "\
684
+ "Version/4.0 UCBrowser/11.3.8.976 U3/0.8.0 Mobile Safari/534.30",
685
+ ]
686
+
687
+ INCOMPATIBLE_USER_AGENTS.each do |user_agent|
688
+ it "user agent #{user_agent} is correctly marked as incompatible" do
689
+ sniffer = BrowserSniffer.new(user_agent)
690
+
691
+ refute sniffer.same_site_none_compatible?
692
+ end
693
+ end
694
+
695
+ COMPATIBLE_USER_AGENTS = [
696
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117"\
697
+ " Safari/537.36",
698
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0",
699
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4"\
700
+ " Safari/605.1.15",
701
+ ]
702
+
703
+ COMPATIBLE_USER_AGENTS.each do |user_agent|
704
+ it "user agent #{user_agent} is correctly marked as compatible" do
705
+ sniffer = BrowserSniffer.new(user_agent)
706
+
707
+ assert sniffer.same_site_none_compatible?
708
+ end
709
+ end
606
710
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser_sniffer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-06 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubyforge_project:
99
- rubygems_version: 2.7.6
98
+ rubygems_version: 3.0.3
100
99
  signing_key:
101
100
  specification_version: 4
102
101
  summary: Parses user agent strings and boils it all down to a few simple classifications.