forked from kolide/launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forward request from custom handler to localserver
- Loading branch information
1 parent
bafd23f
commit e500e70
Showing
3 changed files
with
137 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//go:build darwin | ||
// +build darwin | ||
|
||
package customprotocol | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_extractRequestPath(t *testing.T) { | ||
t.Parallel() | ||
|
||
for _, tt := range []struct { | ||
testCaseName string | ||
requestUrl string | ||
expectedPath string | ||
expectedError bool | ||
}{ | ||
{ | ||
testCaseName: "valid request", | ||
requestUrl: "kolide://local/v3/cmd?box=abcd", | ||
expectedPath: "/v3/cmd?box=abcd", | ||
expectedError: false, | ||
}, | ||
{ | ||
testCaseName: "valid request, no query", | ||
requestUrl: "kolide://local/v4/cmd", | ||
expectedPath: "/v4/cmd", | ||
expectedError: false, | ||
}, | ||
{ | ||
testCaseName: "invalid request", | ||
requestUrl: string(rune(0x7f)), // invalid control character in URL | ||
expectedPath: "", | ||
expectedError: true, | ||
}, | ||
} { | ||
tt := tt | ||
t.Run(tt.testCaseName, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
reqPath, err := extractRequestPath(tt.requestUrl) | ||
if tt.expectedError { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
require.Equal(t, tt.expectedPath, reqPath) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters