1
0
mirror of https://github.com/arduino/library-registry.git synced 2025-07-09 01:42:00 +03:00

Add check for submission URL being a Git repository

With the current submission system, it's common for people to provide the tag/release URL rather than the repository
URL. I think it likely the same sort of thing will occur with the new system. Previously, a very naive check was done
for the path component of the URL to have two levels. It turns out that the Gitlab repository URLs have more levels than
that. The superior approach is to use `git ls-remote` to verify that the URL is a Git repository.
This commit is contained in:
per1234
2021-01-19 14:26:52 -08:00
parent 3fc5f76339
commit 0ca9ab8ee7
2 changed files with 23 additions and 33 deletions

View File

@ -13,7 +13,6 @@
package main
import (
"fmt"
"net/url"
"testing"
@ -154,14 +153,11 @@ func Test_normalizeURL(t *testing.T) {
testName string
rawURL string
expectedNormalizedURL string
expectedError string
}{
{"Trailing slash", "https://github.com/foo/bar/", "https://github.com/foo/bar.git", ""},
{".git suffix", "https://github.com/foo/bar.git", "https://github.com/foo/bar.git", ""},
{"Too few path elements", "https://github.com/foo", "", "Submission URL must point to the root of the repository"},
{"Too many path elements", "https://github.com/foo/bar/baz", "", "Submission URL must point to the root of the repository"},
{"http://", "http://github.com/foo/bar", "https://github.com/foo/bar.git", ""},
{"git://", "git://github.com/foo/bar", "https://github.com/foo/bar.git", ""},
{"Trailing slash", "https://github.com/foo/bar/", "https://github.com/foo/bar.git"},
{".git suffix", "https://github.com/foo/bar.git", "https://github.com/foo/bar.git"},
{"http://", "http://github.com/foo/bar", "https://github.com/foo/bar.git"},
{"git://", "git://github.com/foo/bar", "https://github.com/foo/bar.git"},
}
for _, testTable := range testTables {
@ -170,13 +166,7 @@ func Test_normalizeURL(t *testing.T) {
expectedNormalizedURL, err := url.Parse(testTable.expectedNormalizedURL)
require.Nil(t, err)
normalizedURL, err := normalizeURL(rawURL)
assert.Equal(t, *expectedNormalizedURL, normalizedURL, testTable.testName)
if testTable.expectedError == "" {
assert.Nil(t, err, testTable.testName)
} else {
assert.Equal(t, fmt.Errorf(testTable.expectedError), err, testTable.testName)
}
assert.Equal(t, *expectedNormalizedURL, normalizeURL(rawURL), testTable.testName)
}
}