From fd85f873f36483dacbf6e635412fb78cf17fc6ba Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 23 Jul 2021 14:12:14 -0700 Subject: [PATCH] Add library type check to registry data file validator There was previously no validation of this field. --- .../assets/validate-registry/main.go | 21 +++++++++++++++++++ .../validate-registry/tests/test_all.py | 2 ++ .../tests/testdata/invalid-type.txt | 3 +++ .../tests/testdata/no-type.txt | 3 +++ 4 files changed, 29 insertions(+) create mode 100644 .github/workflows/assets/validate-registry/tests/testdata/invalid-type.txt create mode 100644 .github/workflows/assets/validate-registry/tests/testdata/no-type.txt diff --git a/.github/workflows/assets/validate-registry/main.go b/.github/workflows/assets/validate-registry/main.go index 52acb177..742d49c1 100644 --- a/.github/workflows/assets/validate-registry/main.go +++ b/.github/workflows/assets/validate-registry/main.go @@ -43,8 +43,29 @@ func main() { os.Exit(1) } + validTypes := map[string]bool{ + "Arduino": true, + "Contributed": true, + "Partner": true, + "Recommended": true, + "Retired": true, + } + nameMap := make(map[string]bool) for _, entry := range rawRepos { + // Check entry types + if len(entry.Types) == 0 { + fmt.Fprintf(os.Stderr, "error: Type not specified for library \"%s\"\n", entry.LibraryName) + os.Exit(1) + } + for _, entryType := range entry.Types { + if _, valid := validTypes[entryType]; !valid { + fmt.Fprintf(os.Stderr, "error: Invalid type \"%s\" used by library \"%s\"\n", entryType, entry.LibraryName) + os.Exit(1) + } + } + + // Check library name of the entry if _, found := nameMap[entry.LibraryName]; found { fmt.Fprintf(os.Stderr, "error: Registry data file contains duplicates of name %s\n", entry.LibraryName) os.Exit(1) diff --git a/.github/workflows/assets/validate-registry/tests/test_all.py b/.github/workflows/assets/validate-registry/tests/test_all.py index 8b86851a..c3c7b150 100644 --- a/.github/workflows/assets/validate-registry/tests/test_all.py +++ b/.github/workflows/assets/validate-registry/tests/test_all.py @@ -30,6 +30,8 @@ test_data_path = pathlib.Path(__file__).resolve().parent.joinpath("testdata") ("nonexistent.txt", False), ("invalid-data-format.txt", False), ("invalid-url-format.txt", False), + ("no-type.txt", False), + ("invalid-type.txt", False), ("duplicate-url.txt", False), ("duplicate-name.txt", False), ("valid.txt", True), diff --git a/.github/workflows/assets/validate-registry/tests/testdata/invalid-type.txt b/.github/workflows/assets/validate-registry/tests/testdata/invalid-type.txt new file mode 100644 index 00000000..5cae8ae9 --- /dev/null +++ b/.github/workflows/assets/validate-registry/tests/testdata/invalid-type.txt @@ -0,0 +1,3 @@ +https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler +https://github.com/arduino-libraries/SD.git|foo|SD +https://github.com/arduino-libraries/Servo.git|Recommended|Servo diff --git a/.github/workflows/assets/validate-registry/tests/testdata/no-type.txt b/.github/workflows/assets/validate-registry/tests/testdata/no-type.txt new file mode 100644 index 00000000..5c592dc2 --- /dev/null +++ b/.github/workflows/assets/validate-registry/tests/testdata/no-type.txt @@ -0,0 +1,3 @@ +https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler +https://github.com/arduino-libraries/SD.git||SD +https://github.com/arduino-libraries/Servo.git|Recommended|Servo