diff --git a/master/buildbot/steps/source/p4.py b/master/buildbot/steps/source/p4.py index b9747c4bed4..86161cd98b7 100644 --- a/master/buildbot/steps/source/p4.py +++ b/master/buildbot/steps/source/p4.py @@ -201,11 +201,11 @@ def _buildVCCommand(self, doCommand): command.extend(['-p', self.p4port]) if self.p4user: command.extend(['-u', self.p4user]) - if self.p4client: - command.extend(['-c', self.p4client]) if not self.use_tickets and self.p4passwd: # Need to find out if there's a way to obfuscate this command.extend(['-P', self.p4passwd]) + if self.p4client: + command.extend(['-c', self.p4client]) # Only add the extra arguments for the `sync` command. if doCommand[0] == 'sync' and self.p4extra_args: @@ -322,6 +322,7 @@ def _acquireTicket(self, _): if debug_logging: log.msg("P4:acquireTicket()") + # TODO: check first if the ticket is still valid? initialStdin = self.p4passwd + "\n" yield self._dovccmd(['login'], initialStdin=initialStdin) diff --git a/master/buildbot/test/unit/test_steps_source_p4.py b/master/buildbot/test/unit/test_steps_source_p4.py index 37b394ec4f9..ca110cdf48a 100644 --- a/master/buildbot/test/unit/test_steps_source_p4.py +++ b/master/buildbot/test/unit/test_steps_source_p4.py @@ -722,3 +722,63 @@ def test_mode_full_p4extra_args(self): \t//depot/trunk/... //p4_client1/... ''' % root_dir) self._full(client_stdin=client_spec, extra_args=['-Zproxyload']) + + + def test_ticket_auth(self): + self.setupStep(P4(p4port='localhost:12000', + p4base='//depot', p4branch='trunk', + p4user='user', p4client='p4_client1', p4passwd='pass', use_tickets=True)) + + root_dir = '/home/user/workspace/wkdir' + if _is_windows: + root_dir = r'C:\Users\username\Workspace\wkdir' + client_spec = textwrap.dedent('''\ + Client: p4_client1 + + Owner: user + + Description: + \tCreated by user + + Root:\t%s + + Options:\tallwrite rmdir + + LineEnd:\tlocal + + View: + \t//depot/trunk/... //p4_client1/... + ''' % root_dir) + + self.expectCommands( + ExpectShell(workdir='wkdir', command=['p4', '-V']) + + 0, + + # This is the extra step that gets run when using tickets, + # and the password is not passed anymore after that. + ExpectShell(workdir='wkdir', + command=['p4', '-p', 'localhost:12000', '-u', 'user', + '-c', 'p4_client1', + 'login'], + initialStdin='pass\n') + + 0, + + ExpectShell(workdir='wkdir', + command=['p4', '-p', 'localhost:12000', '-u', 'user', + '-c', 'p4_client1', + 'client', '-i'], + initialStdin=client_spec) + + 0, + ExpectShell(workdir='wkdir', + command=(['p4', '-p', 'localhost:12000', '-u', 'user', + '-c', 'p4_client1', 'sync'])) + + 0, + ExpectShell(workdir='wkdir', + command=['p4', '-p', 'localhost:12000', '-u', 'user', + '-c', 'p4_client1', + 'changes', '-m1', '#have']) + + ExpectShell.log('stdio', + stdout="Change 100 on 2013/03/21 by user@machine \'duh\'") + + 0, + ) + self.runStep()