Skip to content

Commit 75315bf

Browse files
committed
cURL escape authenticators (fixes #89)
1 parent a25373f commit 75315bf

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

authenticators/DigestAuthenticator.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ End Sub
122122
''
123123
Private Sub IWebAuthenticator_PrepareCurl(ByVal Client As WebClient, ByVal Request As WebRequest, ByRef Curl As String)
124124
' http://curl.haxx.se/docs/manpage.html#--digest
125-
Curl = Curl & " --digest --user " & Me.Username & ":" & Me.Password
125+
Curl = Curl & " --digest --user " & WebHelpers.PrepareTextForShell(Me.Username) & ":" & WebHelpers.PrepareTextForShell(Me.Password)
126126
End Sub
127127

128128
''

authenticators/HttpBasicAuthenticator.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ End Sub
9191
''
9292
Private Sub IWebAuthenticator_PrepareCurl(ByVal Client As WebClient, ByVal Request As WebRequest, ByRef Curl As String)
9393
' e.g. Add flags to cURL
94-
Curl = Curl & " --basic --user " & Me.Username & ":" & Me.Password
94+
Curl = Curl & " --basic --user " & WebHelpers.PrepareTextForShell(Me.Username) & ":" & WebHelpers.PrepareTextForShell(Me.Password)
9595
End Sub
9696

specs/Specs_HttpBasicAuthenticator.bas

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Public Function Specs() As SpecSuite
2525
Request.AddUrlSegment "user", "Tim"
2626
Request.AddUrlSegment "password", "Secret123"
2727

28+
Set Client.Authenticator = Nothing
2829
Set Response = Client.Execute(Request)
2930
.Expect(Response.StatusCode).ToEqual WebStatusCode.Unauthorized
3031

@@ -36,6 +37,24 @@ Public Function Specs() As SpecSuite
3637
.Expect(Response.Data("authenticated")).ToEqual True
3738
End With
3839

40+
With Specs.It("should properly escape username and password")
41+
Set Request = New WebRequest
42+
Request.Resource = "basic-auth/{user}/{password}"
43+
Request.AddUrlSegment "user", "Tim\`$""!"
44+
Request.AddUrlSegment "password", "Secret123\`$""!"
45+
46+
Set Client.Authenticator = Nothing
47+
Set Response = Client.Execute(Request)
48+
.Expect(Response.StatusCode).ToEqual WebStatusCode.Unauthorized
49+
50+
Auth.Setup "Tim\`$""!", "Secret123\`$""!"
51+
Set Client.Authenticator = Auth
52+
53+
Set Response = Client.Execute(Request)
54+
.Expect(Response.StatusCode).ToEqual 200
55+
.Expect(Response.Data("authenticated")).ToEqual True
56+
End With
57+
3958
InlineRunner.RunSuite Specs
4059
End Function
4160

specs/Specs_WebHelpers.bas

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ Public Function Specs() As SpecSuite
399399
' ============================================= '
400400
' 7. Mac
401401
' ============================================= '
402-
403-
#If Mac Then
402+
404403
' ExecuteInShell
405404

406405
' PrepareTextForShell
@@ -410,7 +409,6 @@ Public Function Specs() As SpecSuite
410409
.Expect(WebHelpers.PrepareTextForShell("!abc!123!")).ToEqual "'!'""abc""'!'""123""'!'"
411410
.Expect(WebHelpers.PrepareTextForShell("`!$\""%")).ToEqual """\`""'!'""\$\\\""\%"""
412411
End With
413-
#End If
414412

415413
' ============================================= '
416414
' 8. Cryptography

src/WebHelpers.bas

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,6 @@ End Sub
14141414
' ============================================= '
14151415
' 7. Mac
14161416
' ============================================= '
1417-
#If Mac Then
14181417

14191418
''
14201419
' Execute the given command
@@ -1425,6 +1424,7 @@ End Sub
14251424
' @return {ShellResult}
14261425
''
14271426
Public Function ExecuteInShell(web_Command As String) As ShellResult
1427+
#If Mac Then
14281428
Dim web_File As Long
14291429
Dim web_Chunk As String
14301430
Dim web_Read As Long
@@ -1450,6 +1450,7 @@ Public Function ExecuteInShell(web_Command As String) As ShellResult
14501450
web_Cleanup:
14511451

14521452
ExecuteInShell.ExitCode = web_pclose(web_File)
1453+
#End If
14531454
End Function
14541455

14551456
''
@@ -1488,8 +1489,6 @@ Public Function PrepareTextForShell(ByVal web_Text As String) As String
14881489
PrepareTextForShell = web_Text
14891490
End Function
14901491

1491-
#End If
1492-
14931492
' ============================================= '
14941493
' 8. Cryptography
14951494
' ============================================= '

0 commit comments

Comments
 (0)