22
33require 'rails_helper'
44require 'google/protobuf/well_known_types'
5+ require 'grpc/health/v1/health_services_pb'
56
67RSpec . describe Sagittarius ::Middleware ::Grpc ::Authentication do
78 let ( :rpc_class ) do
@@ -45,11 +46,20 @@ def test(_msg, _call)
4546 end . to raise_error ( GRPC ::Unauthenticated )
4647 end
4748 # rubocop:enable Lint/EmptyBlock
49+
50+ context 'when anonymous service is called' do
51+ let ( :service_class ) { Grpc ::Health ::V1 ::Health ::Service }
52+ let ( :method ) { service_class . new . method ( :check ) }
53+
54+ it do
55+ expect { |b | interceptor . request_response ( request : request , call : call , method : method , &b ) } . to yield_control
56+ end
57+ end
4858 end
4959
5060 context 'when invalid authentication is passed' do
5161 let ( :metadata ) do
52- { authorization : 'token' }
62+ { ' authorization' => 'token' }
5363 end
5464
5565 # rubocop:disable Lint/EmptyBlock -- the block is part of the api and needs to be given
@@ -59,6 +69,19 @@ def test(_msg, _call)
5969 end . to raise_error ( GRPC ::Unauthenticated )
6070 end
6171 # rubocop:enable Lint/EmptyBlock
72+
73+ context 'when anonymous service is called' do
74+ let ( :service_class ) { Grpc ::Health ::V1 ::Health ::Service }
75+ let ( :method ) { service_class . new . method ( :check ) }
76+
77+ # rubocop:disable Lint/EmptyBlock -- the block is part of the api and needs to be given
78+ it do
79+ expect do
80+ interceptor . request_response ( request : request , call : call , method : method ) { }
81+ end . to raise_error ( GRPC ::Unauthenticated )
82+ end
83+ # rubocop:enable Lint/EmptyBlock
84+ end
6285 end
6386
6487 context 'when valid authentication is passed' do
@@ -77,6 +100,15 @@ def test(_msg, _call)
77100 namespace_id : nil } )
78101 end
79102 # rubocop:enable Lint/EmptyBlock
103+
104+ context 'when anonymous service is called' do
105+ let ( :service_class ) { Grpc ::Health ::V1 ::Health ::Service }
106+ let ( :method ) { service_class . new . method ( :check ) }
107+
108+ it do
109+ expect { |b | interceptor . request_response ( request : request , call : call , method : method , &b ) } . to yield_control
110+ end
111+ end
80112 end
81113 end
82114
@@ -93,7 +125,7 @@ def test(_msg, _call)
93125
94126 context 'when invalid authentication is passed' do
95127 let ( :metadata ) do
96- { authorization : 'token' }
128+ { ' authorization' => 'token' }
97129 end
98130
99131 # rubocop:disable Lint/EmptyBlock -- the block is part of the api and needs to be given
@@ -137,7 +169,7 @@ def test(_msg, _call)
137169
138170 context 'when invalid authentication is passed' do
139171 let ( :metadata ) do
140- { authorization : 'token' }
172+ { ' authorization' => 'token' }
141173 end
142174
143175 # rubocop:disable Lint/EmptyBlock -- the block is part of the api and needs to be given
@@ -181,7 +213,7 @@ def test(_msg, _call)
181213
182214 context 'when invalid authentication is passed' do
183215 let ( :metadata ) do
184- { authorization : 'token' }
216+ { ' authorization' => 'token' }
185217 end
186218
187219 # rubocop:disable Lint/EmptyBlock -- the block is part of the api and needs to be given
0 commit comments