snowplow_ruby_duid 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +22 -0
- data/.github/workflows/dobby-actions.yml +29 -0
- data/.github/workflows/gem-publish.yml +46 -0
- data/.github/workflows/version-forget-me-not.yml +19 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +14 -1
- data/.rubocop_todo.yml +73 -0
- data/.ruby-version +1 -0
- data/.semaphore/semaphore.yml +39 -0
- data/catalog-info.yaml +11 -0
- data/lib/snowplow_ruby_duid/configuration.rb +1 -1
- data/lib/snowplow_ruby_duid/cookie.rb +2 -2
- data/lib/snowplow_ruby_duid/grape_helper.rb +56 -0
- data/lib/snowplow_ruby_duid/helper.rb +1 -1
- data/lib/snowplow_ruby_duid/version.rb +1 -1
- data/snowplow_ruby_duid.gemspec +2 -3
- data/spec/lib/snowplow_ruby_duid/cookie_spec.rb +4 -3
- data/spec/lib/snowplow_ruby_duid/helper_spec.rb +8 -5
- data/spec/snowplow_ruby_duid/grape_helper_spec.rb +77 -0
- metadata +20 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 642dc9820122d6381e3043b571a0bf3633cf486df13f665a52237f165a07bfa6
|
4
|
+
data.tar.gz: f1644da529eb04eaa064db4cd65e9e5b3a0ab32abfc158b6626872e431c37956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c52efc015d166a16e97f65fee67609d57b78e07a34c6abaab982be9b085e611462b5b52db9dc112cff052a718eaf371e3065c4bd9d111fac15841e7d962280e
|
7
|
+
data.tar.gz: e60531d4de07ae4c5a2a9fb99fd3b8e1c3fb284ff8c6670fecc67b6645d1b9d9e3a3cc98c3c092416c797bd389b28533ec115a48c00a1933d5edab9711dd1117
|
@@ -0,0 +1,22 @@
|
|
1
|
+
version: 2
|
2
|
+
updates:
|
3
|
+
- package-ecosystem: bundler
|
4
|
+
directory: "/"
|
5
|
+
schedule:
|
6
|
+
interval: daily
|
7
|
+
time: "07:00"
|
8
|
+
open-pull-requests-limit: 99
|
9
|
+
labels:
|
10
|
+
- dependencies
|
11
|
+
ignore:
|
12
|
+
- dependency-name: simplecov
|
13
|
+
versions:
|
14
|
+
- ">= 0.18"
|
15
|
+
- package-ecosystem: github-actions
|
16
|
+
directory: "/"
|
17
|
+
schedule:
|
18
|
+
interval: daily
|
19
|
+
time: "07:00"
|
20
|
+
open-pull-requests-limit: 99
|
21
|
+
labels:
|
22
|
+
- dependencies
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
name: "Dobby action"
|
3
|
+
on:
|
4
|
+
issue_comment:
|
5
|
+
types: [created]
|
6
|
+
permissions:
|
7
|
+
contents: read
|
8
|
+
jobs:
|
9
|
+
pr_commented:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
if: startsWith(github.event.comment.body, '/dobby')
|
12
|
+
env:
|
13
|
+
BUNDLE_WITHOUT: "development:test"
|
14
|
+
steps:
|
15
|
+
- name: Chekcout action
|
16
|
+
uses: actions/checkout@v4
|
17
|
+
with:
|
18
|
+
repository: 'simplybusiness/dobby'
|
19
|
+
ref: 'v4'
|
20
|
+
- name: Set up ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
bundler-cache: true
|
24
|
+
- name: Bump version
|
25
|
+
uses: simplybusiness/dobby@v4
|
26
|
+
env:
|
27
|
+
DOBBY_APP_ID: ${{ secrets.DOBBY_APP_ID }}
|
28
|
+
DOBBY_PRIVATE_KEY: ${{ secrets.DOBBY_PRIVATE_KEY }}
|
29
|
+
VERSION_FILE_PATH: lib/snowplow_ruby_duid/version.rb
|
@@ -0,0 +1,46 @@
|
|
1
|
+
name: Deploy Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
|
7
|
+
permissions:
|
8
|
+
contents: write
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
name: Build and Publish
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v4
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
bundler-cache: true
|
20
|
+
- name: Publish to RubyGems
|
21
|
+
run: |
|
22
|
+
mkdir -p $HOME/.gem
|
23
|
+
touch $HOME/.gem/credentials
|
24
|
+
chmod 0600 $HOME/.gem/credentials
|
25
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
26
|
+
gem build *.gemspec
|
27
|
+
gem push *.gem
|
28
|
+
env:
|
29
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
30
|
+
- name: Get Gem Version
|
31
|
+
id: get-gem-version
|
32
|
+
run: echo "GEM_VERSION=$(bundle exec ruby -e 'puts SnowplowRubyDuid::VERSION')" >> $GITHUB_OUTPUT
|
33
|
+
- name: Create Release
|
34
|
+
uses: actions/github-script@v7
|
35
|
+
env:
|
36
|
+
GEM_VERSION: ${{ steps.get-gem-version.outputs.GEM_VERSION }}
|
37
|
+
with:
|
38
|
+
result-encoding: string
|
39
|
+
script: |
|
40
|
+
const { GEM_VERSION } = process.env
|
41
|
+
github.rest.repos.createRelease({
|
42
|
+
owner: context.repo.owner,
|
43
|
+
repo: context.repo.repo,
|
44
|
+
tag_name: GEM_VERSION,
|
45
|
+
generate_release_notes: true,
|
46
|
+
})
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: Check version
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
types: [opened, synchronize]
|
8
|
+
permissions:
|
9
|
+
contents: read
|
10
|
+
statuses: write
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: simplybusiness/version-forget-me-not@v2
|
17
|
+
env:
|
18
|
+
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
19
|
+
VERSION_FILE_PATH: "lib/snowplow_ruby_duid/version.rb"
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
inherit_from: .rubocop_todo.yml
|
3
|
+
|
4
|
+
inherit_gem:
|
5
|
+
simplycop:
|
6
|
+
- .simplycop.yml
|
7
|
+
- .simplycop_performance.yml
|
8
|
+
- .simplycop_rspec.yml
|
9
|
+
|
10
|
+
Layout/LineLength:
|
2
11
|
Enabled: false
|
3
12
|
|
4
13
|
Style/BlockDelimiters:
|
@@ -12,3 +21,7 @@ Metrics/BlockLength:
|
|
12
21
|
Style/DateTime:
|
13
22
|
Exclude:
|
14
23
|
- 'lib/snowplow_ruby_duid/cookie.rb'
|
24
|
+
|
25
|
+
Gemspec/RequiredRubyVersion:
|
26
|
+
Exclude:
|
27
|
+
- 'snowplow_ruby_duid.gemspec'
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2025-07-31 06:50:56 UTC using RuboCop version 1.79.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
CustomCops/TimecopWithoutBlock:
|
11
|
+
Exclude:
|
12
|
+
- 'spec/lib/snowplow_ruby_duid/helper_spec.rb'
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
# Configuration parameters: AllowComments, AllowEmptyLambdas.
|
16
|
+
Lint/EmptyBlock:
|
17
|
+
Exclude:
|
18
|
+
- 'spec/lib/snowplow_ruby_duid/cookie_spec.rb'
|
19
|
+
|
20
|
+
# Offense count: 1
|
21
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
22
|
+
# Configuration parameters: MaxKeyValuePairs.
|
23
|
+
Performance/RedundantMerge:
|
24
|
+
Exclude:
|
25
|
+
- 'lib/snowplow_ruby_duid/cookie.rb'
|
26
|
+
|
27
|
+
# Offense count: 1
|
28
|
+
RSpec/AnyInstance:
|
29
|
+
Exclude:
|
30
|
+
- 'spec/lib/snowplow_ruby_duid/helper_spec.rb'
|
31
|
+
|
32
|
+
# Offense count: 2
|
33
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
34
|
+
RSpec/BeEq:
|
35
|
+
Exclude:
|
36
|
+
- 'spec/lib/snowplow_ruby_duid/cookie_spec.rb'
|
37
|
+
|
38
|
+
# Offense count: 2
|
39
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
40
|
+
# Configuration parameters: AutoCorrect.
|
41
|
+
RSpec/EmptyExampleGroup:
|
42
|
+
Exclude:
|
43
|
+
- 'spec/lib/snowplow_ruby_duid/cookie_spec.rb'
|
44
|
+
- 'spec/lib/snowplow_ruby_duid/helper_spec.rb'
|
45
|
+
|
46
|
+
# Offense count: 2
|
47
|
+
RSpec/MissingExampleGroupArgument:
|
48
|
+
Exclude:
|
49
|
+
- 'spec/lib/snowplow_ruby_duid/cookie_spec.rb'
|
50
|
+
- 'spec/lib/snowplow_ruby_duid/helper_spec.rb'
|
51
|
+
|
52
|
+
# Offense count: 5
|
53
|
+
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
|
54
|
+
# SupportedStyles: always, named_only
|
55
|
+
RSpec/NamedSubject:
|
56
|
+
Exclude:
|
57
|
+
- 'spec/lib/snowplow_ruby_duid/cookie_spec.rb'
|
58
|
+
- 'spec/lib/snowplow_ruby_duid/domain_userid_spec.rb'
|
59
|
+
- 'spec/lib/snowplow_ruby_duid/helper_spec.rb'
|
60
|
+
|
61
|
+
# Offense count: 1
|
62
|
+
# Configuration parameters: SuspiciousParamNames, Allowlist.
|
63
|
+
# SuspiciousParamNames: options, opts, args, params, parameters
|
64
|
+
Style/OptionHash:
|
65
|
+
Exclude:
|
66
|
+
- 'lib/snowplow_ruby_duid/cookie.rb'
|
67
|
+
|
68
|
+
# Offense count: 1
|
69
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
70
|
+
# Configuration parameters: Mode.
|
71
|
+
Style/StringConcatenation:
|
72
|
+
Exclude:
|
73
|
+
- 'lib/snowplow_ruby_duid/cookie.rb'
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.4.5
|
@@ -0,0 +1,39 @@
|
|
1
|
+
version: v1.0
|
2
|
+
name: Semaphore v2 tests
|
3
|
+
agent:
|
4
|
+
machine:
|
5
|
+
type: f1-standard-2
|
6
|
+
os_image: ubuntu2204
|
7
|
+
auto_cancel:
|
8
|
+
running:
|
9
|
+
when: branch != 'master'
|
10
|
+
global_job_config:
|
11
|
+
prologue:
|
12
|
+
commands:
|
13
|
+
- checkout
|
14
|
+
- 'cache restore bundle-$SEMAPHORE_GIT_BRANCH-$SEMAPHORE_WORKFLOW_ID,bundle-$SEMAPHORE_GIT_BRANCH,bundle-master'
|
15
|
+
- 'bundle config gemstash.simplybusiness.io $GEMSTASH_USER:$GEMSTASH_PASSWORD'
|
16
|
+
- bundle install --path vendor/bundle
|
17
|
+
- bundle clean --force
|
18
|
+
- cache store bundle-$SEMAPHORE_GIT_BRANCH-$SEMAPHORE_WORKFLOW_ID vendor/bundle
|
19
|
+
blocks:
|
20
|
+
- name: Semaphore v2 tests
|
21
|
+
dependencies: []
|
22
|
+
execution_time_limit:
|
23
|
+
minutes: 10
|
24
|
+
task:
|
25
|
+
jobs:
|
26
|
+
- name: Rspec job
|
27
|
+
commands:
|
28
|
+
- bundle exec rspec
|
29
|
+
- name: Semaphore v2 Compliance
|
30
|
+
dependencies: []
|
31
|
+
skip:
|
32
|
+
when: branch = 'master'
|
33
|
+
execution_time_limit:
|
34
|
+
minutes: 10
|
35
|
+
task:
|
36
|
+
jobs:
|
37
|
+
- name: Rubocop
|
38
|
+
commands:
|
39
|
+
- bundle exec rubocop
|
data/catalog-info.yaml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
apiVersion: backstage.io/v1alpha1
|
2
|
+
kind: Component
|
3
|
+
metadata:
|
4
|
+
name: snowplow_ruby_duid
|
5
|
+
title: Snowplow Ruby DUID
|
6
|
+
description: A gem that exposes the Snowplow domain userid in Rack applications. Also allows you to set your own domain userid that will be shared with the Snowplow Javascript tracker.
|
7
|
+
annotations:
|
8
|
+
rubygems.org/name: "snowplow_ruby_duid"
|
9
|
+
spec:
|
10
|
+
type: library
|
11
|
+
lifecycle: production
|
@@ -4,7 +4,7 @@ module SnowplowRubyDuid
|
|
4
4
|
# This is the configuration object that is used for two additional cookie settings
|
5
5
|
# that can't be deferred from the request/response objects
|
6
6
|
module Configuration
|
7
|
-
@allowed =
|
7
|
+
@allowed = [:none, :lax, :strict]
|
8
8
|
|
9
9
|
@same_site = :lax
|
10
10
|
@secure = false
|
@@ -9,7 +9,7 @@ module SnowplowRubyDuid
|
|
9
9
|
# See: https://github.com/snowplow/snowplow-javascript-tracker/blob/d3d10067127eb5c95d0054c8ae60f3bdccba619d/src/js/tracker.js#L156
|
10
10
|
COOKIE_DURATION_MONTHS = 24
|
11
11
|
# See: https://github.com/rails/rails/blob/b1124a2ac88778c0feb0157ac09367cbd204bf01/actionpack/lib/action_dispatch/middleware/cookies.rb#L214
|
12
|
-
DOMAIN_REGEXP = /[^.]*\.([^.]*|..\...|...\...)
|
12
|
+
DOMAIN_REGEXP = /[^.]*\.([^.]*|..\...|...\...)$/o
|
13
13
|
|
14
14
|
def initialize(host, domain_userid, request_created_at, options = {})
|
15
15
|
@host = host
|
@@ -46,7 +46,7 @@ module SnowplowRubyDuid
|
|
46
46
|
|
47
47
|
# See: https://github.com/rails/rails/blob/b1124a2ac88778c0feb0157ac09367cbd204bf01/actionpack/lib/action_dispatch/middleware/cookies.rb#L286-L294
|
48
48
|
def top_level_domain
|
49
|
-
|
49
|
+
::Regexp.last_match(0) if (@host !~ /^[\d.]+$/) && (@host =~ DOMAIN_REGEXP)
|
50
50
|
end
|
51
51
|
|
52
52
|
# See: https://github.com/snowplow/snowplow-javascript-tracker/blob/d3d10067127eb5c95d0054c8ae60f3bdccba619d/src/js/tracker.js#L476-L487
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SnowplowRubyDuid
|
4
|
+
# This is the same as SnowplowRubyDuid::Helper, except it handles the HTTP
|
5
|
+
# objects that the Grape API (https://github.com/ruby-grape/grape) exposes
|
6
|
+
# (`response`, `request`, `request.cookies`) in an appropriate manner.
|
7
|
+
|
8
|
+
COOKIE_PREFIX_PATTERN = /^#{KEY_PREFIX}/o
|
9
|
+
|
10
|
+
module GrapeHelper
|
11
|
+
def snowplow_domain_userid
|
12
|
+
@snowplow_domain_userid ||= find_or_create_snowplow_domain_userid
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def find_or_create_snowplow_domain_userid
|
18
|
+
find_snowplow_domain_userid || create_snowplow_domain_userid
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_snowplow_domain_userid
|
22
|
+
request_created_at = Time.now
|
23
|
+
domain_userid = DomainUserid.new.to_s
|
24
|
+
options = {
|
25
|
+
secure: Configuration.secure,
|
26
|
+
same_site: Configuration.same_site
|
27
|
+
}
|
28
|
+
snowplow_cookie = Cookie.new request.host, domain_userid, request_created_at, options
|
29
|
+
|
30
|
+
# Grape has no "response" object but uses the `header` DSL or the `cookies` local var
|
31
|
+
# header 'Set-Cookie', "#{snowplow_cookie.key}=#{snowplow_cookie.value}; Path=/; HttpOnly"
|
32
|
+
cookies[snowplow_cookie.key] = snowplow_cookie.value
|
33
|
+
domain_userid
|
34
|
+
end
|
35
|
+
|
36
|
+
# See: https://docs.snowplow.io/docs/sources/trackers/ruby-tracker/adding-data-events/#cookie-based-user-properties
|
37
|
+
def find_snowplow_domain_userid
|
38
|
+
snowplow_cookie = find_snowplow_cookie # [key, value] format
|
39
|
+
# The cookie value format: domainUserId.createTs.visitCount.nowTs.lastVisitTs
|
40
|
+
snowplow_cookie.last.split('.').first unless snowplow_cookie.nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
# @uses request[Grape::Cookies] Not a real parameter, but comes from the code this is mixed into.
|
44
|
+
# @return [Hash{string => string}, nil] Snowplow cookie key/value or nil if not found.
|
45
|
+
def find_snowplow_cookie
|
46
|
+
snowplow_cookie = nil
|
47
|
+
request.cookies.each do |(key, value)|
|
48
|
+
if COOKIE_PREFIX_PATTERN.match?(key)
|
49
|
+
snowplow_cookie = [key, value]
|
50
|
+
break
|
51
|
+
end
|
52
|
+
end
|
53
|
+
snowplow_cookie
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -36,7 +36,7 @@ module SnowplowRubyDuid
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def find_snowplow_cookie
|
39
|
-
request.cookies.find { |(key, _value)| key =~ /^#{KEY_PREFIX}/ } # result will be an array containing: [key, value]
|
39
|
+
request.cookies.find { |(key, _value)| key =~ /^#{KEY_PREFIX}/o } # result will be an array containing: [key, value]
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/snowplow_ruby_duid.gemspec
CHANGED
@@ -16,14 +16,13 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
19
|
spec.require_paths = ['lib']
|
21
20
|
|
22
21
|
spec.add_development_dependency 'rack'
|
23
22
|
spec.add_development_dependency 'rack-test'
|
24
|
-
spec.add_development_dependency 'rake', '
|
23
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
25
24
|
spec.add_development_dependency 'rspec'
|
26
|
-
spec.add_development_dependency 'rubocop'
|
27
25
|
spec.add_development_dependency 'rutabaga'
|
26
|
+
spec.add_development_dependency 'simplycop'
|
28
27
|
spec.add_development_dependency 'timecop'
|
29
28
|
end
|
@@ -32,7 +32,7 @@ module SnowplowRubyDuid
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
describe do
|
36
36
|
step 'the host is :host' do |host|
|
37
37
|
@host = host
|
38
38
|
end
|
@@ -46,7 +46,7 @@ module SnowplowRubyDuid
|
|
46
46
|
end
|
47
47
|
|
48
48
|
step 'I configure library and set secure cookie to :val' do |setting|
|
49
|
-
@secure = (setting == 'true') if
|
49
|
+
@secure = (setting == 'true') if ['true', 'false'].include?(setting)
|
50
50
|
end
|
51
51
|
|
52
52
|
step 'the cookie\'s secure setting is :set_not_set' do |value|
|
@@ -57,7 +57,8 @@ module SnowplowRubyDuid
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
step 'I create a Snowplow cookie' do
|
60
|
+
step 'I create a Snowplow cookie' do
|
61
|
+
end
|
61
62
|
|
62
63
|
step 'the cookie has the path :path' do |path|
|
63
64
|
expect(subject.value[:path]).to eq(path)
|
@@ -9,16 +9,19 @@ module SnowplowRubyDuid
|
|
9
9
|
include Rack::Test::Methods
|
10
10
|
|
11
11
|
describe 'snowplow_domain_userid' do
|
12
|
-
let(:app) {
|
12
|
+
let(:app) { HelperTestApp.new }
|
13
|
+
|
13
14
|
before do
|
14
15
|
Timecop.freeze(Time.local(1990))
|
15
16
|
end
|
17
|
+
|
16
18
|
after do
|
17
19
|
Timecop.return
|
18
20
|
end
|
19
|
-
subject { last_response.header['Set-Cookie'] }
|
20
21
|
|
21
|
-
|
22
|
+
subject { last_response.headers['Set-Cookie'] }
|
23
|
+
|
24
|
+
describe do
|
22
25
|
step 'I set a Snowplow domain userid of :domain_userid in my cookie' do |domain_userid|
|
23
26
|
set_cookie("_sp_id.3678=#{domain_userid}.631152000.0.631152000.631152000") unless domain_userid == ''
|
24
27
|
end
|
@@ -63,7 +66,7 @@ module SnowplowRubyDuid
|
|
63
66
|
end
|
64
67
|
end
|
65
68
|
|
66
|
-
class
|
69
|
+
class HelperTestApp
|
67
70
|
include SnowplowRubyDuid::Helper
|
68
71
|
|
69
72
|
attr_reader :request, :response, :domain_userid
|
@@ -75,6 +78,6 @@ class App
|
|
75
78
|
|
76
79
|
@domain_userid = snowplow_domain_userid
|
77
80
|
|
78
|
-
[response.status, response.
|
81
|
+
[response.status, response.headers, response.body]
|
79
82
|
end
|
80
83
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'snowplow_ruby_duid/grape_helper'
|
4
|
+
require 'timecop'
|
5
|
+
|
6
|
+
require 'rspec'
|
7
|
+
RSpec.describe 'SnowplowRubyDuid::GrapeHelper' do
|
8
|
+
context 'when the cookie has been set before' do
|
9
|
+
let(:test_app) { GrapeHelperSpecTestApp.new }
|
10
|
+
let(:snowplow_cookie_id) { '_sp_id.79723' }
|
11
|
+
let(:snowplow_cookie_value) { 'domainUserId.createTs.visitCount.nowTs.lastVisitTs' }
|
12
|
+
|
13
|
+
before do
|
14
|
+
test_app.request.cookies[snowplow_cookie_id] = snowplow_cookie_value
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'finds the cookie and returns the domain id' do
|
18
|
+
expect(test_app.snowplow_domain_userid).to eq('domainUserId')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when the cookie has not been set before' do
|
23
|
+
let(:test_app) { GrapeHelperSpecTestApp.new }
|
24
|
+
|
25
|
+
before do
|
26
|
+
Timecop.freeze(Time.local(2025, 2, 1, 10, 0, 0)) # rubocop:disable CustomCops/TimecopWithoutBlock
|
27
|
+
end
|
28
|
+
|
29
|
+
after do
|
30
|
+
Timecop.return
|
31
|
+
end
|
32
|
+
|
33
|
+
it "creates a new domain id cookie if one doesn't exist" do
|
34
|
+
# Start with empty cookies.
|
35
|
+
expect(test_app.request.cookies).to eq({})
|
36
|
+
|
37
|
+
got_userid = test_app.snowplow_domain_userid
|
38
|
+
# These are random/uuids, but have this format: "60bde8c9-8047-410c-97a8-d73af82f90fe"
|
39
|
+
expect(got_userid).to match(/^([0-9a-fA-F]+-){4}[0-9a-fA-F]+$/)
|
40
|
+
|
41
|
+
# cookies should now be filled with the one created.
|
42
|
+
retrieved_cookies = test_app.request.cookies
|
43
|
+
expect(retrieved_cookies.size).to eq(1)
|
44
|
+
|
45
|
+
# We know there's only one cookie here, so just use that for the test.
|
46
|
+
aggregate_failures 'cookie structure' do
|
47
|
+
# format is [key, value]
|
48
|
+
cookie_key = retrieved_cookies.first[0]
|
49
|
+
expect(cookie_key).to start_with(SnowplowRubyDuid::KEY_PREFIX)
|
50
|
+
|
51
|
+
cookie_value = retrieved_cookies.first[1]
|
52
|
+
expect(cookie_value).to be_a(Hash)
|
53
|
+
expect(cookie_value[:value]).to start_with(got_userid)
|
54
|
+
# Timecop frozen "now" + 2 years
|
55
|
+
expect(cookie_value[:expires].to_s.encode('US-ASCII')).to start_with('2027-02-01 10:00:00'.encode('US-ASCII'))
|
56
|
+
expect(cookie_value[:domain]).to eq('.example.com')
|
57
|
+
expect(cookie_value[:path]).to eq('/')
|
58
|
+
expect(cookie_value[:same_site]).to eq(:lax)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# What we're testing is a Mixin, so mix it in to something we control
|
65
|
+
# the methods that the Mixin uses (cookies, request.cookies, request.host). We don't
|
66
|
+
# need ACTUAL Grape things here, just things that act the same way.
|
67
|
+
class GrapeHelperSpecTestApp
|
68
|
+
include SnowplowRubyDuid::GrapeHelper
|
69
|
+
|
70
|
+
attr_reader :request
|
71
|
+
|
72
|
+
def initialize
|
73
|
+
@request = Struct.new(:cookies, :host).new({}, 'example.com')
|
74
|
+
end
|
75
|
+
|
76
|
+
def cookies = @request.cookies
|
77
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snowplow_ruby_duid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simply Business
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rack
|
@@ -42,16 +41,16 @@ dependencies:
|
|
42
41
|
name: rake
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
|
-
- - "
|
44
|
+
- - ">="
|
46
45
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
46
|
+
version: 12.3.3
|
48
47
|
type: :development
|
49
48
|
prerelease: false
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
51
50
|
requirements:
|
52
|
-
- - "
|
51
|
+
- - ">="
|
53
52
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
53
|
+
version: 12.3.3
|
55
54
|
- !ruby/object:Gem::Dependency
|
56
55
|
name: rspec
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +66,7 @@ dependencies:
|
|
67
66
|
- !ruby/object:Gem::Version
|
68
67
|
version: '0'
|
69
68
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
69
|
+
name: rutabaga
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
72
71
|
requirements:
|
73
72
|
- - ">="
|
@@ -81,7 +80,7 @@ dependencies:
|
|
81
80
|
- !ruby/object:Gem::Version
|
82
81
|
version: '0'
|
83
82
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
83
|
+
name: simplycop
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
86
85
|
requirements:
|
87
86
|
- - ">="
|
@@ -117,17 +116,26 @@ executables: []
|
|
117
116
|
extensions: []
|
118
117
|
extra_rdoc_files: []
|
119
118
|
files:
|
119
|
+
- ".github/dependabot.yml"
|
120
|
+
- ".github/workflows/dobby-actions.yml"
|
121
|
+
- ".github/workflows/gem-publish.yml"
|
122
|
+
- ".github/workflows/version-forget-me-not.yml"
|
120
123
|
- ".gitignore"
|
121
124
|
- ".rspec"
|
122
125
|
- ".rubocop.yml"
|
126
|
+
- ".rubocop_todo.yml"
|
127
|
+
- ".ruby-version"
|
128
|
+
- ".semaphore/semaphore.yml"
|
123
129
|
- Gemfile
|
124
130
|
- LICENSE.txt
|
125
131
|
- README.md
|
126
132
|
- Rakefile
|
133
|
+
- catalog-info.yaml
|
127
134
|
- lib/snowplow_ruby_duid.rb
|
128
135
|
- lib/snowplow_ruby_duid/configuration.rb
|
129
136
|
- lib/snowplow_ruby_duid/cookie.rb
|
130
137
|
- lib/snowplow_ruby_duid/domain_userid.rb
|
138
|
+
- lib/snowplow_ruby_duid/grape_helper.rb
|
131
139
|
- lib/snowplow_ruby_duid/helper.rb
|
132
140
|
- lib/snowplow_ruby_duid/version.rb
|
133
141
|
- snowplow_ruby_duid.gemspec
|
@@ -136,12 +144,12 @@ files:
|
|
136
144
|
- spec/lib/snowplow_ruby_duid/domain_userid_spec.rb
|
137
145
|
- spec/lib/snowplow_ruby_duid/helper.feature
|
138
146
|
- spec/lib/snowplow_ruby_duid/helper_spec.rb
|
147
|
+
- spec/snowplow_ruby_duid/grape_helper_spec.rb
|
139
148
|
- spec/spec_helper.rb
|
140
149
|
homepage: https://github.com/simplybusiness/snowplow_ruby_duid
|
141
150
|
licenses:
|
142
151
|
- MIT
|
143
152
|
metadata: {}
|
144
|
-
post_install_message:
|
145
153
|
rdoc_options: []
|
146
154
|
require_paths:
|
147
155
|
- lib
|
@@ -156,16 +164,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
164
|
- !ruby/object:Gem::Version
|
157
165
|
version: '0'
|
158
166
|
requirements: []
|
159
|
-
rubygems_version: 3.
|
160
|
-
signing_key:
|
167
|
+
rubygems_version: 3.6.9
|
161
168
|
specification_version: 4
|
162
169
|
summary: A gem that exposes the Snowplow domain userid in Rack applications. Also
|
163
170
|
allows you to set your own domain userid that will be shared with the Snowplow Javascript
|
164
171
|
tracker.
|
165
|
-
test_files:
|
166
|
-
- spec/lib/snowplow_ruby_duid/cookie.feature
|
167
|
-
- spec/lib/snowplow_ruby_duid/cookie_spec.rb
|
168
|
-
- spec/lib/snowplow_ruby_duid/domain_userid_spec.rb
|
169
|
-
- spec/lib/snowplow_ruby_duid/helper.feature
|
170
|
-
- spec/lib/snowplow_ruby_duid/helper_spec.rb
|
171
|
-
- spec/spec_helper.rb
|
172
|
+
test_files: []
|