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
a8d71143
Commit
a8d71143
authored
May 11, 2021
by
Vladlena Shumilo
Committed by
Kerri Miller
May 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix SyncSeatLinkRequestWorker license duplication
parent
186c51b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
19 deletions
+64
-19
ee/app/workers/sync_seat_link_request_worker.rb
ee/app/workers/sync_seat_link_request_worker.rb
+8
-3
ee/spec/workers/sync_seat_link_request_worker_spec.rb
ee/spec/workers/sync_seat_link_request_worker_spec.rb
+56
-16
No files found.
ee/app/workers/sync_seat_link_request_worker.rb
View file @
a8d71143
...
...
@@ -24,7 +24,7 @@ class SyncSeatLinkRequestWorker
)
if
response
.
success?
create_license
(
response
[
'license'
])
if
response
[
'license'
]
reset_license!
(
response
[
'license'
])
if
response
[
'license'
]
else
raise
RequestError
,
request_error_message
(
response
)
end
...
...
@@ -32,8 +32,13 @@ class SyncSeatLinkRequestWorker
private
def
create_license
(
license_data
)
License
.
create!
(
data:
license_data
,
cloud:
true
)
def
reset_license!
(
license_data
)
current_license
=
License
.
current
if
License
.
current
&
.
cloud_license?
License
.
transaction
do
current_license
&
.
destroy!
License
.
create!
(
data:
license_data
,
cloud:
true
)
end
rescue
StandardError
=>
e
Gitlab
::
ErrorTracking
.
track_and_raise_for_dev_exception
(
e
)
end
...
...
ee/spec/workers/sync_seat_link_request_worker_spec.rb
View file @
a8d71143
...
...
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec
.
describe
SyncSeatLinkRequestWorker
,
type: :worker
do
describe
'#perform'
do
subject
do
subject
(
:sync_seat_link
)
do
described_class
.
new
.
perform
(
'2020-01-01T01:20:12+02:00'
,
'123'
,
5
,
4
)
end
...
...
@@ -13,7 +13,7 @@ RSpec.describe SyncSeatLinkRequestWorker, type: :worker do
it
'makes an HTTP POST request with passed params'
do
stub_request
(
:post
,
seat_link_url
).
to_return
(
status:
200
)
s
ubject
s
ync_seat_link
expect
(
WebMock
).
to
have_requested
(
:post
,
seat_link_url
).
with
(
headers:
{
'Content-Type'
=>
'application/json'
},
...
...
@@ -38,36 +38,76 @@ RSpec.describe SyncSeatLinkRequestWorker, type: :worker do
body:
body
,
headers:
{
content_type:
'application/json'
}
)
allow
(
License
).
to
receive
(
:current
).
and_return
(
current_license
)
end
it
'persists returned license'
do
expect
{
subject
}.
to
change
(
License
,
:count
).
by
(
1
)
expect
(
License
.
last
).
to
have_attributes
(
data:
license_key
,
cloud:
true
)
shared_examples
'successful license creation'
do
it
'persists the new license'
do
expect
{
sync_seat_link
}.
to
change
(
License
,
:count
).
by
(
1
)
expect
(
License
.
last
).
to
have_attributes
(
data:
license_key
,
cloud:
true
)
end
end
context
'when persisting fails'
do
let
(
:license_key
)
{
'invalid-key'
}
context
'when there is no previous license'
do
let
(
:current_license
)
{
nil
}
it_behaves_like
'successful license creation'
end
context
'when there is a previous license'
do
context
'when it is a cloud license'
do
let
(
:current_license
)
{
create
(
:license
,
cloud:
true
)
}
it
'persists the new license and deletes the current one'
do
expect
{
sync_seat_link
}.
not_to
change
(
License
,
:count
)
expect
(
License
.
last
).
to
have_attributes
(
data:
license_key
,
cloud:
true
)
expect
(
License
).
not_to
exist
(
current_license
.
id
)
end
context
'when persisting fails'
do
let
(
:license_key
)
{
'invalid-key'
}
it
'does not delete the current license and logs error'
do
expect
(
Gitlab
::
ErrorTracking
).
to
receive
(
:track_and_raise_for_dev_exception
).
and_call_original
expect
{
sync_seat_link
}.
to
raise_error
expect
(
License
).
to
exist
(
current_license
.
id
)
end
end
context
'when deleting fails'
do
it
'does not create a new license and logs error'
do
last_license
=
License
.
last
allow
(
current_license
).
to
receive
(
:destroy!
).
and_raise
expect
(
Gitlab
::
ErrorTracking
).
to
receive
(
:track_and_raise_for_dev_exception
).
and_call_original
expect
{
sync_seat_link
}.
to
raise_error
expect
(
License
.
last
).
to
eq
(
last_license
)
end
end
end
it
'logs error
'
do
expect
(
Gitlab
::
ErrorTracking
).
to
receive
(
:track_and_raise_for_dev_exception
).
and_call_original
context
'when it is not a cloud license
'
do
let
(
:current_license
)
{
create
(
:license
)
}
expect
{
subject
}.
to
raise_error
it_behaves_like
'successful license creation'
end
end
end
context
'with old date format string'
do
subject
do
subject
(
:sync_seat_link
)
do
described_class
.
new
.
perform
(
'2020-01-01'
,
'123'
,
5
,
4
)
end
it
'makes an HTTP POST request with passed params'
do
stub_request
(
:post
,
seat_link_url
).
to_return
(
status:
200
)
s
ubject
s
ync_seat_link
expect
(
WebMock
).
to
have_requested
(
:post
,
seat_link_url
).
with
(
headers:
{
'Content-Type'
=>
'application/json'
},
...
...
@@ -91,7 +131,7 @@ RSpec.describe SyncSeatLinkRequestWorker, type: :worker do
end
it
'raises an error with the expected message'
do
expect
{
s
ubject
}.
to
raise_error
(
expect
{
s
ync_seat_link
}.
to
raise_error
(
described_class
::
RequestError
,
'Seat Link request failed! Code:400 Body:{"success":false,"error":"Bad Request"}'
)
...
...
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