91
91
self.get_server().add_user(getpass.getuser(), self.password)
92
92
t = self.get_transport()
93
ui.ui_factory = tests.TestUIFactory(stdin=self.password + '\n',
94
stdout=tests.StringIOWrapper())
93
ui.ui_factory = ui.CannedInputUIFactory([self.password])
95
94
# Issue a request to the server to connect
96
95
t.put_bytes('foo', 'test bytes\n')
97
96
self.assertEqual('test bytes\n', t.get_bytes('foo'))
98
97
# Only the password should've been read
99
self.assertEqual('', ui.ui_factory.stdin.readline())
98
ui.ui_factory.assert_all_input_consumed()
101
100
def test_prompt_for_password(self):
102
101
t = self.get_transport()
103
ui.ui_factory = tests.TestUIFactory(stdin=self.password+'\n',
104
stdout=tests.StringIOWrapper())
102
ui.ui_factory = ui.CannedInputUIFactory([self.password])
105
103
# Issue a request to the server to connect
106
104
t.has('whatever/not/existing')
107
105
# stdin should be empty (the provided password have been consumed)
108
self.assertEqual('', ui.ui_factory.stdin.readline())
106
ui.ui_factory.assert_all_input_consumed()
110
108
def test_no_prompt_for_password_when_using_auth_config(self):
111
109
t = self.get_transport()
112
ui.ui_factory = tests.TestUIFactory(stdin='precious\n',
113
stdout=tests.StringIOWrapper())
110
ui.ui_factory = ui.CannedInputUIFactory([])
114
111
# Create a config file with the right password
115
112
conf = config.AuthenticationConfig()
116
113
conf._get_config().update({'ftptest': {'scheme': 'ftp',
120
117
# Issue a request to the server to connect
121
118
t.put_bytes('foo', 'test bytes\n')
122
119
self.assertEqual('test bytes\n', t.get_bytes('foo'))
123
# stdin should have been left untouched
124
self.assertEqual('precious\n', ui.ui_factory.stdin.readline())
126
121
def test_empty_password(self):
127
122
# Override the default user/password from setUp
129
124
self.password = ''
130
125
self.get_server().add_user(self.user, self.password)
131
126
t = self.get_transport()
132
ui.ui_factory = tests.TestUIFactory(stdin=self.password+'\n',
133
stdout=tests.StringIOWrapper())
127
ui.ui_factory = ui.CannedInputUIFactory([self.password])
134
128
# Issue a request to the server to connect
135
129
t.has('whatever/not/existing')
136
130
# stdin should be empty (the provided password have been consumed),
137
131
# even if the password is empty, it's followed by a newline.
138
self.assertEqual('', ui.ui_factory.stdin.readline())
132
ui.ui_factory.assert_all_input_consumed()