Skip to content

Commit

Permalink
Added unit test for ticket auth in P4 source step.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicchabant committed Jun 6, 2014
1 parent 2a896fe commit ab4e40d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
5 changes: 3 additions & 2 deletions master/buildbot/steps/source/p4.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
60 changes: 60 additions & 0 deletions master/buildbot/test/unit/test_steps_source_p4.py
Expand Up @@ -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()

0 comments on commit ab4e40d

Please sign in to comment.