-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to pull in rules from remote repos (#122)
Co-authored-by: Mary Kate Comer <mkcomer@RYPETERS-CON.redmond.corp.microsoft.com> Co-authored-by: Mary Kate Comer <mkcomer@Marys-MacBook-Pro.local> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: MK Comer <mcomer@microsoft.com>
- Loading branch information
1 parent
da6e23b
commit c5a39fe
Showing
4 changed files
with
121 additions
and
4 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
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,22 @@ | ||
package config | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// isValidUrl tests a string to determine if it is a valid URL or not | ||
func isValidURL(toTest string) bool { | ||
_, err := url.ParseRequestURI(toTest) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
u, err := url.Parse(toTest) | ||
if err != nil || u.Scheme == "" || u.Host == "" { | ||
return false | ||
} | ||
log.Debug().Str("remoteConfig", toTest).Msg("Valid URL for remote config.") | ||
return true | ||
} |
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,34 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_isValidURL(t *testing.T) { | ||
t.Run("valid-url-test1", func(t *testing.T) { | ||
boolResponse := isValidURL("https://raw.githubusercontent.com/get-woke/woke/main/example.yaml") | ||
assert.True(t, boolResponse) | ||
}) | ||
|
||
t.Run("invalid-url-test1", func(t *testing.T) { | ||
boolResponse := isValidURL("Users/Document/test.yaml") | ||
assert.False(t, boolResponse) | ||
}) | ||
|
||
t.Run("invalid-url-test2", func(t *testing.T) { | ||
boolResponse := isValidURL("/Users/Document/test.yaml") | ||
assert.False(t, boolResponse) | ||
}) | ||
|
||
t.Run("invalid-url-test3", func(t *testing.T) { | ||
boolResponse := isValidURL("C:User\testpath\test.yaml") | ||
assert.False(t, boolResponse) | ||
}) | ||
|
||
t.Run("invalid-url-test4", func(t *testing.T) { | ||
boolResponse := isValidURL("C:\\directory.com\test.yaml") | ||
assert.False(t, boolResponse) | ||
}) | ||
} |