Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8d26442b
Commit
8d26442b
authored
Apr 30, 2021
by
Nicolas Dular
Committed by
David Fernandez
Apr 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not set experiment cookie on self managed
parent
d058aeb3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
10 deletions
+41
-10
changelogs/unreleased/nicolasdular-do-not-set-experiment-cookie-on-self-managed.yml
...lasdular-do-not-set-experiment-cookie-on-self-managed.yml
+5
-0
lib/gitlab/experimentation/controller_concern.rb
lib/gitlab/experimentation/controller_concern.rb
+12
-7
spec/lib/gitlab/experimentation/controller_concern_spec.rb
spec/lib/gitlab/experimentation/controller_concern_spec.rb
+24
-3
No files found.
changelogs/unreleased/nicolasdular-do-not-set-experiment-cookie-on-self-managed.yml
0 → 100644
View file @
8d26442b
---
title
:
Do not set experiment cookie on self managed and delete existing cookies
merge_request
:
60419
author
:
type
:
fixed
lib/gitlab/experimentation/controller_concern.rb
View file @
8d26442b
...
@@ -19,6 +19,7 @@ module Gitlab
...
@@ -19,6 +19,7 @@ module Gitlab
end
end
def
set_experimentation_subject_id_cookie
def
set_experimentation_subject_id_cookie
if
Gitlab
.
dev_env_or_com?
return
if
cookies
[
:experimentation_subject_id
].
present?
return
if
cookies
[
:experimentation_subject_id
].
present?
cookies
.
permanent
.
signed
[
:experimentation_subject_id
]
=
{
cookies
.
permanent
.
signed
[
:experimentation_subject_id
]
=
{
...
@@ -26,6 +27,10 @@ module Gitlab
...
@@ -26,6 +27,10 @@ module Gitlab
secure:
::
Gitlab
.
config
.
gitlab
.
https
,
secure:
::
Gitlab
.
config
.
gitlab
.
https
,
httponly:
true
httponly:
true
}
}
else
# We set the cookie before, although experiments are not conducted on self managed instances.
cookies
.
delete
(
:experimentation_subject_id
)
end
end
end
def
push_frontend_experiment
(
experiment_key
,
subject:
nil
)
def
push_frontend_experiment
(
experiment_key
,
subject:
nil
)
...
...
spec/lib/gitlab/experimentation/controller_concern_spec.rb
View file @
8d26442b
...
@@ -19,12 +19,15 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
...
@@ -19,12 +19,15 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
}
}
)
)
allow
(
Gitlab
).
to
receive
(
:dev_env_or_com?
).
and_return
(
is_gitlab_com
)
Feature
.
enable_percentage_of_time
(
:backwards_compatible_test_experiment_experiment_percentage
,
enabled_percentage
)
Feature
.
enable_percentage_of_time
(
:backwards_compatible_test_experiment_experiment_percentage
,
enabled_percentage
)
Feature
.
enable_percentage_of_time
(
:test_experiment_experiment_percentage
,
enabled_percentage
)
Feature
.
enable_percentage_of_time
(
:test_experiment_experiment_percentage
,
enabled_percentage
)
end
end
let
(
:enabled_percentage
)
{
10
}
let
(
:enabled_percentage
)
{
10
}
let
(
:rollout_strategy
)
{
nil
}
let
(
:rollout_strategy
)
{
nil
}
let
(
:is_gitlab_com
)
{
true
}
controller
(
ApplicationController
)
do
controller
(
ApplicationController
)
do
include
Gitlab
::
Experimentation
::
ControllerConcern
include
Gitlab
::
Experimentation
::
ControllerConcern
...
@@ -37,17 +40,17 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
...
@@ -37,17 +40,17 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
describe
'#set_experimentation_subject_id_cookie'
do
describe
'#set_experimentation_subject_id_cookie'
do
let
(
:do_not_track
)
{
nil
}
let
(
:do_not_track
)
{
nil
}
let
(
:cookie
)
{
cookies
.
permanent
.
signed
[
:experimentation_subject_id
]
}
let
(
:cookie
)
{
cookies
.
permanent
.
signed
[
:experimentation_subject_id
]
}
let
(
:cookie_value
)
{
nil
}
before
do
before
do
request
.
headers
[
'DNT'
]
=
do_not_track
if
do_not_track
.
present?
request
.
headers
[
'DNT'
]
=
do_not_track
if
do_not_track
.
present?
request
.
cookies
[
:experimentation_subject_id
]
=
cookie_value
if
cookie_value
get
:index
get
:index
end
end
context
'cookie is present'
do
context
'cookie is present'
do
before
do
let
(
:cookie_value
)
{
'test'
}
cookies
[
:experimentation_subject_id
]
=
'test'
end
it
'does not change the cookie'
do
it
'does not change the cookie'
do
expect
(
cookies
[
:experimentation_subject_id
]).
to
eq
'test'
expect
(
cookies
[
:experimentation_subject_id
]).
to
eq
'test'
...
@@ -75,6 +78,24 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
...
@@ -75,6 +78,24 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
end
end
end
end
end
end
context
'when not on gitlab.com'
do
let
(
:is_gitlab_com
)
{
false
}
context
'when cookie was set'
do
let
(
:cookie_value
)
{
'test'
}
it
'cookie gets deleted'
do
expect
(
cookie
).
not_to
be_present
end
end
context
'when no cookie was set before'
do
it
'does nothing'
do
expect
(
cookie
).
not_to
be_present
end
end
end
end
end
describe
'#push_frontend_experiment'
do
describe
'#push_frontend_experiment'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment