@@ -354,6 +354,64 @@ def test_shell_args_cacert_insecure(self):
354354 self .assertFalse (self .requests_mock .request_history [0 ].verify )
355355
356356
357+ class TestShellCliV3Prompt (TestShellInteg ):
358+
359+ def setUp (self ):
360+ super (TestShellCliV3Prompt , self ).setUp ()
361+ env = {
362+ "OS_AUTH_URL" : V3_AUTH_URL ,
363+ "OS_PROJECT_DOMAIN_ID" : test_shell .DEFAULT_PROJECT_DOMAIN_ID ,
364+ "OS_USER_DOMAIN_ID" : test_shell .DEFAULT_USER_DOMAIN_ID ,
365+ "OS_USERNAME" : test_shell .DEFAULT_USERNAME ,
366+ "OS_IDENTITY_API_VERSION" : "3" ,
367+ }
368+ self .useFixture (osc_lib_utils .EnvFixture (copy .deepcopy (env )))
369+
370+ self .token = ksa_fixture .V3Token (
371+ project_domain_id = test_shell .DEFAULT_PROJECT_DOMAIN_ID ,
372+ user_domain_id = test_shell .DEFAULT_USER_DOMAIN_ID ,
373+ user_name = test_shell .DEFAULT_USERNAME ,
374+ )
375+
376+ # Set up the v3 auth routes
377+ self .requests_mock .register_uri (
378+ 'GET' ,
379+ V3_AUTH_URL ,
380+ json = V3_VERSION_RESP ,
381+ status_code = 200 ,
382+ )
383+ self .requests_mock .register_uri (
384+ 'POST' ,
385+ V3_AUTH_URL + 'auth/tokens' ,
386+ json = self .token ,
387+ status_code = 200 ,
388+ )
389+
390+ @mock .patch ("osc_lib.shell.prompt_for_password" )
391+ def test_shell_callback (self , mock_prompt ):
392+ mock_prompt .return_value = "qaz"
393+ _shell = shell .OpenStackShell ()
394+ _shell .run ("configuration show" .split ())
395+
396+ # Check general calls
397+ self .assertEqual (len (self .requests_mock .request_history ), 2 )
398+
399+ # Check password callback set correctly
400+ self .assertEqual (
401+ mock_prompt ,
402+ _shell .cloud ._openstack_config ._pw_callback
403+ )
404+
405+ # Check auth request
406+ auth_req = self .requests_mock .request_history [1 ].json ()
407+
408+ # Check returned password from prompt function
409+ self .assertEqual (
410+ "qaz" ,
411+ auth_req ['auth' ]['identity' ]['password' ]['user' ]['password' ],
412+ )
413+
414+
357415class TestShellCliPrecedence (TestShellInteg ):
358416 """Validate option precedence rules without clouds.yaml
359417
0 commit comments