@@ -258,5 +258,42 @@ module Vault
258258 subject . auth . aws_iam ( 'a_rolename' , credentials_provider , 'iam_header_canary' , 'https://sts.cn-north-1.amazonaws.com.cn' )
259259 end
260260 end
261+
262+ describe "#gcp" , vault : ">= 0.8.1" do
263+ before ( :context ) do
264+ vault_test_client . sys . enable_auth ( "gcp" , "gcp" , nil )
265+ vault_test_client . post ( "/v1/auth/gcp/config" , JSON . fast_generate ( "service_account" => "rspec_service_account" ) )
266+ vault_test_client . post ( "/v1/auth/gcp/role/rspec_wrong_role" , JSON . fast_generate ( "name" => "rspec_role" , "project_id" => "wrong_project_id" , "bound_service_accounts" => "\* " , "type" => "iam" ) )
267+ vault_test_client . post ( "/v1/auth/gcp/role/rspec_role" , JSON . fast_generate ( "name" => "rspec_role" , "project_id" => "project_id" , "bound_service_accounts" => "\* " , "type" => "iam" ) )
268+ end
269+
270+ after ( :context ) do
271+ vault_test_client . sys . disable_auth ( "gcp" )
272+ end
273+
274+ let! ( :old_token ) { subject . token }
275+
276+ let ( :jwt ) do
277+ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJwcm9qZWN0X2lkIjoicHJvamVjdF9pZCJ9.TmuiSHtbLMZuw_LOzKWQ2vnC7BUvu2b4CeBXdxCDCXQ"
278+ end
279+
280+ after do
281+ subject . token = old_token
282+ end
283+
284+ it "does not authenticate if project_id does not match" do
285+ pending "gcp auth requires real resources and keys"
286+
287+ expect do
288+ subject . auth . gcp ( "rspec_wrong_role" , jwt )
289+ end . to raise_error ( Vault ::HTTPClientError , /project_id doesn't match/ )
290+ end
291+
292+ it "authenticates and saves the token on the client" do
293+ pending "gcp auth requires real resources and keys"
294+
295+ subject . auth . gcp ( "rspec_role" , jwt )
296+ end
297+ end
261298 end
262299end
0 commit comments