## Motivation and Context - Add MCPB as a new registry_name option - Add file_hashes field to package model for integrity verification - Implement URL validation restricting MCPB packages to GitHub/GitLab hosts - Require SHA-256 hash for all MCPB packages - Add example MCPB package in documentation - Update schemas and OpenAPI specification See issue #260 ## How Has This Been Tested? <!-- Have you tested this in a real application? Which scenarios were tested? --> ## Breaking Changes N/A, registry has not yet been launched ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [ ] My code follows the repository's style guidelines - [ ] New and existing tests pass locally - [ ] I have added appropriate error handling - [x] I have added or updated documentation as needed --------- Co-authored-by: Adam Jones <adamj+git@anthropic.com>
252 lines
6.2 KiB
Go
252 lines
6.2 KiB
Go
package validators_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/modelcontextprotocol/registry/internal/model"
|
|
"github.com/modelcontextprotocol/registry/internal/validators"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestObjectValidator_Validate(t *testing.T) {
|
|
validator := validators.NewObjectValidator()
|
|
|
|
tests := []struct {
|
|
name string
|
|
serverDetail model.ServerDetail
|
|
expectedError string
|
|
}{
|
|
{
|
|
name: "valid server detail with all fields",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://github.com/owner/repo",
|
|
Source: "github",
|
|
ID: "owner/repo",
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
Packages: []model.Package{
|
|
{
|
|
Identifier: "test-package",
|
|
RegistryType: "npm",
|
|
RegistryBaseURL: "https://registry.npmjs.org",
|
|
},
|
|
},
|
|
Remotes: []model.Remote{
|
|
{
|
|
URL: "https://example.com/remote",
|
|
},
|
|
},
|
|
},
|
|
expectedError: "",
|
|
},
|
|
{
|
|
name: "server with invalid repository source",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://bitbucket.org/owner/repo",
|
|
Source: "bitbucket", // Not in validSources
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
},
|
|
expectedError: validators.ErrInvalidRepositoryURL.Error(),
|
|
},
|
|
{
|
|
name: "server with invalid GitHub URL format",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://github.com/owner", // Missing repo name
|
|
Source: "github",
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
},
|
|
expectedError: validators.ErrInvalidRepositoryURL.Error(),
|
|
},
|
|
{
|
|
name: "server with invalid GitLab URL format",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://gitlab.com", // Missing owner and repo
|
|
Source: "gitlab",
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
},
|
|
expectedError: validators.ErrInvalidRepositoryURL.Error(),
|
|
},
|
|
{
|
|
name: "package with spaces in name",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://github.com/owner/repo",
|
|
Source: "github",
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
Packages: []model.Package{
|
|
{
|
|
Identifier: "test package with spaces",
|
|
RegistryType: "npm",
|
|
RegistryBaseURL: "https://registry.npmjs.org",
|
|
},
|
|
},
|
|
},
|
|
expectedError: validators.ErrPackageNameHasSpaces.Error(),
|
|
},
|
|
{
|
|
name: "multiple packages with one invalid",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://github.com/owner/repo",
|
|
Source: "github",
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
Packages: []model.Package{
|
|
{
|
|
Identifier: "valid-package",
|
|
RegistryType: "npm",
|
|
RegistryBaseURL: "https://registry.npmjs.org",
|
|
},
|
|
{
|
|
Identifier: "invalid package", // Has space
|
|
RegistryType: "pypi",
|
|
RegistryBaseURL: "https://pypi.org",
|
|
},
|
|
},
|
|
},
|
|
expectedError: validators.ErrPackageNameHasSpaces.Error(),
|
|
},
|
|
{
|
|
name: "remote with invalid URL",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://github.com/owner/repo",
|
|
Source: "github",
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
Remotes: []model.Remote{
|
|
{
|
|
URL: "not-a-valid-url",
|
|
},
|
|
},
|
|
},
|
|
expectedError: validators.ErrInvalidRemoteURL.Error(),
|
|
},
|
|
{
|
|
name: "remote with missing scheme",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://github.com/owner/repo",
|
|
Source: "github",
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
Remotes: []model.Remote{
|
|
{
|
|
URL: "example.com/remote",
|
|
},
|
|
},
|
|
},
|
|
expectedError: validators.ErrInvalidRemoteURL.Error(),
|
|
},
|
|
{
|
|
name: "multiple remotes with one invalid",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://github.com/owner/repo",
|
|
Source: "github",
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
Remotes: []model.Remote{
|
|
{
|
|
URL: "https://valid.com/remote",
|
|
},
|
|
{
|
|
URL: "invalid-url",
|
|
},
|
|
},
|
|
},
|
|
expectedError: validators.ErrInvalidRemoteURL.Error(),
|
|
},
|
|
{
|
|
name: "server detail with nil packages and remotes",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://github.com/owner/repo",
|
|
Source: "github",
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
Packages: nil,
|
|
Remotes: nil,
|
|
},
|
|
expectedError: "",
|
|
},
|
|
{
|
|
name: "server detail with empty packages and remotes slices",
|
|
serverDetail: model.ServerDetail{
|
|
Name: "test-server",
|
|
Description: "A test server",
|
|
Repository: model.Repository{
|
|
URL: "https://github.com/owner/repo",
|
|
Source: "github",
|
|
},
|
|
VersionDetail: model.VersionDetail{
|
|
Version: "1.0.0",
|
|
},
|
|
Packages: []model.Package{},
|
|
Remotes: []model.Remote{},
|
|
},
|
|
expectedError: "",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := validator.Validate(&tt.serverDetail)
|
|
|
|
if tt.expectedError == "" {
|
|
assert.NoError(t, err)
|
|
} else {
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), tt.expectedError)
|
|
}
|
|
})
|
|
}
|
|
}
|