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
70e75a41
Commit
70e75a41
authored
Jun 30, 2021
by
Ethan Urie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec to test #interceptors is called
parent
51e4d80d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
lib/gitlab/spamcheck/client.rb
lib/gitlab/spamcheck/client.rb
+8
-6
spec/lib/gitlab/spamcheck/client_spec.rb
spec/lib/gitlab/spamcheck/client_spec.rb
+8
-1
No files found.
lib/gitlab/spamcheck/client.rb
View file @
70e75a41
...
...
@@ -27,22 +27,18 @@ module Gitlab
# connect with Spamcheck
@endpoint_url
=
@endpoint_url
.
gsub
(
%r(^grpc:
\/\/
)
,
''
)
creds
=
@
creds
=
if
Rails
.
env
.
development?
||
Rails
.
env
.
test?
:this_channel_is_insecure
else
GRPC
::
Core
::
ChannelCredentials
.
new
end
@stub
=
::
Spamcheck
::
SpamcheckService
::
Stub
.
new
(
@endpoint_url
,
creds
,
interceptors:
interceptors
,
timeout:
DEFAULT_TIMEOUT_SECS
)
end
def
issue_spam?
(
spam_issue
:,
user
:,
context:
{})
issue
=
build_issue_protobuf
(
issue:
spam_issue
,
user:
user
,
context:
context
)
response
=
@stub
.
check_for_spam_issue
(
issue
,
response
=
grpc_client
.
check_for_spam_issue
(
issue
,
metadata:
{
'authorization'
=>
Gitlab
::
CurrentSettings
.
spam_check_api_key
})
verdict
=
convert_verdict_to_gitlab_constant
(
response
.
verdict
)
...
...
@@ -102,6 +98,12 @@ module Gitlab
nanos:
ar_timestamp
.
to_time
.
nsec
)
end
def
grpc_client
@grpc_client
||=
::
Spamcheck
::
SpamcheckService
::
Stub
.
new
(
@endpoint_url
,
@creds
,
interceptors:
interceptors
,
timeout:
DEFAULT_TIMEOUT_SECS
)
end
def
interceptors
[
Labkit
::
Correlation
::
GRPC
::
ClientInterceptor
.
instance
]
end
...
...
spec/lib/gitlab/spamcheck/client_spec.rb
View file @
70e75a41
...
...
@@ -7,7 +7,7 @@ RSpec.describe Gitlab::Spamcheck::Client do
let
(
:endpoint
)
{
'grpc://grpc.test.url'
}
let_it_be
(
:user
)
{
create
(
:user
,
organization:
'GitLab'
)
}
let
(
:verdict_value
)
{
nil
}
let
(
:verdict_value
)
{
::
Spamcheck
::
SpamVerdict
::
Verdict
::
ALLOW
}
let
(
:error_value
)
{
""
}
let
(
:attribs_value
)
do
...
...
@@ -56,6 +56,13 @@ RSpec.describe Gitlab::Spamcheck::Client do
expect
(
subject
).
to
eq
([
expected
,
{
"monitorMode"
=>
"false"
},
""
])
end
end
it
'includes interceptors'
do
expect_next_instance_of
(
::
Gitlab
::
Spamcheck
::
Client
)
do
|
client
|
expect
(
client
).
to
receive
(
:interceptors
).
and_call_original
end
subject
end
end
describe
"#build_issue_protobuf"
,
:aggregate_failures
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