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
75c459e6
Commit
75c459e6
authored
Oct 02, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Unleash API specs
parent
a1c10223
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
116 additions
and
15 deletions
+116
-15
ee/app/models/operations/feature_flags_client.rb
ee/app/models/operations/feature_flags_client.rb
+7
-0
ee/lib/api/unleash.rb
ee/lib/api/unleash.rb
+5
-12
ee/lib/ee/api/entities.rb
ee/lib/ee/api/entities.rb
+5
-1
ee/spec/lib/gitlab/import_export/all_models.yml
ee/spec/lib/gitlab/import_export/all_models.yml
+2
-0
ee/spec/models/project_spec.rb
ee/spec/models/project_spec.rb
+2
-2
ee/spec/requests/api/unleash_spec.rb
ee/spec/requests/api/unleash_spec.rb
+95
-0
No files found.
ee/app/models/operations/feature_flags_client.rb
View file @
75c459e6
...
...
@@ -12,5 +12,12 @@ module Operations
add_authentication_token_field
:token
before_validation
:ensure_token!
def
self
.
find_for_project_and_token
(
project
,
token
)
return
unless
project
return
unless
token
find_by
(
token:
token
,
project:
project
)
end
end
end
ee/lib/api/unleash.rb
View file @
75c459e6
...
...
@@ -10,7 +10,7 @@ module API
end
route_param
:project_id
do
before
do
authenticate_by_unleash_
access_token
!
authenticate_by_unleash_
instanceid
!
end
get
'features'
do
...
...
@@ -36,19 +36,12 @@ module API
end
def
unleash_instanceid
params
[
:instanceid
]
||
env
[
:HTTP_UNLEASH_INSTANCEID
]
params
[
:instanceid
]
||
env
[
'HTTP_UNLEASH_INSTANCEID'
]
end
def
unleash_access_token
return
unless
unleash_instanceid
return
unless
project
@unleash_access_token
||=
Operations
::
FeatureFlagsAccessToken
.
find_by
(
token:
unleash_instanceid
,
project:
project
)
end
def
authenticate_by_unleash_access_token!
unauthorized!
unless
unleash_access_token
def
authenticate_by_unleash_instanceid!
unauthorized!
unless
Operations
::
FeatureFlagsClient
.
find_for_project_and_token
(
project
,
unleash_instanceid
)
end
end
end
...
...
ee/lib/ee/api/entities.rb
View file @
75c459e6
...
...
@@ -436,13 +436,17 @@ module EE
class
UnleashFeatures
<
Grape
::
Entity
expose
:version
expose
:
operations_feature_flags
,
as: :
features
,
with:
UnleashFeature
expose
:features
,
with:
UnleashFeature
private
def
version
1
end
def
features
object
.
operations_feature_flags
.
ordered
end
end
end
end
...
...
ee/spec/lib/gitlab/import_export/all_models.yml
View file @
75c459e6
...
...
@@ -56,6 +56,8 @@ project:
-
vulnerability_feedback
-
vulnerability_identifiers
-
vulnerability_scanners
-
operations_feature_flags
-
operations_feature_flags_instance
-
prometheus_alerts
-
prometheus_alert_events
-
software_license_policies
...
...
ee/spec/models/project_spec.rb
View file @
75c459e6
...
...
@@ -1768,10 +1768,10 @@ describe Project do
end
end
describe
'#feature_flag
_access
_token'
do
describe
'#feature_flag
s_client
_token'
do
let
(
:project
)
{
create
(
:project
)
}
subject
{
project
.
feature_flag
_access
_token
}
subject
{
project
.
feature_flag
s_client
_token
}
context
'when there is no access token'
do
it
"creates a new one"
do
...
...
ee/spec/requests/api/unleash_spec.rb
0 → 100644
View file @
75c459e6
require
'spec_helper'
describe
API
::
Unleash
do
set
(
:project
)
{
create
(
:project
)
}
let
(
:project_id
)
{
project
.
id
}
let
(
:params
)
{
}
let
(
:headers
)
{
}
shared_examples
'authenticated request'
do
context
'when using instanceid'
do
let
(
:client
)
{
create
(
:operations_feature_flags_client
,
project:
project
)
}
let
(
:params
)
{
{
instanceid:
client
.
token
}
}
it
'responds with OK'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
context
'when using header'
do
let
(
:client
)
{
create
(
:operations_feature_flags_client
,
project:
project
)
}
let
(
:headers
)
{
{
"UNLEASH-INSTANCEID"
=>
client
.
token
}}
it
'responds with OK'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
context
'when using bogus instanceid'
do
let
(
:params
)
{
{
instanceid:
'token'
}
}
it
'responds with unauthorized'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
context
'when using not existing project'
do
let
(
:project_id
)
{
-
5000
}
let
(
:params
)
{
{
instanceid:
'token'
}
}
it
'responds with unauthorized'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
end
describe
'GET /feature_flags/unleash/:project_id/features'
do
subject
{
get
api
(
"/feature_flags/unleash/
#{
project_id
}
/features"
),
params
,
headers
}
it_behaves_like
'authenticated request'
context
'with a list of feature flag'
do
let
(
:client
)
{
create
(
:operations_feature_flags_client
,
project:
project
)
}
let
(
:headers
)
{
{
"UNLEASH-INSTANCEID"
=>
client
.
token
}}
let!
(
:enable_feature_flag
)
{
create
(
:operations_feature_flag
,
project:
project
,
name:
'feature1'
,
active:
true
)
}
let!
(
:disabled_feature_flag
)
{
create
(
:operations_feature_flag
,
project:
project
,
name:
'feature2'
,
active:
false
)
}
it
'responds with a list'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'version'
]).
to
eq
(
1
)
expect
(
json_response
[
'features'
]).
not_to
be_empty
expect
(
json_response
[
'features'
].
first
[
'name'
]).
to
eq
(
'feature1'
)
end
it
'matches json schema'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
# TODO: match schema
end
end
end
describe
'POST /feature_flags/unleash/:project_id/client/register'
do
subject
{
post
api
(
"/feature_flags/unleash/
#{
project_id
}
/client/register"
),
params
,
headers
}
it_behaves_like
'authenticated request'
end
describe
'POST /feature_flags/unleash/:project_id/client/metrics'
do
subject
{
post
api
(
"/feature_flags/unleash/
#{
project_id
}
/client/metrics"
),
params
,
headers
}
it_behaves_like
'authenticated request'
end
end
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