From 836e109ee6d058b8d864acffa6f98b78c4ebe365 Mon Sep 17 00:00:00 2001 From: KCarretto Date: Mon, 19 Feb 2024 22:13:50 +0000 Subject: [PATCH] fix bug, add testing --- .../exec_script/metadata.yml | 1 + bin/embedded_files_test/print/metadata.yml | 1 + tavern/internal/ent/schema/repository.go | 2 +- .../createRepository/URLWithHTTPS.yml | 24 +++++++++++++++++++ tavern/tomes/git.go | 7 +++--- tavern/tomes/parse.go | 3 +++ 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tavern/internal/graphql/testdata/mutations/createRepository/URLWithHTTPS.yml diff --git a/bin/embedded_files_test/exec_script/metadata.yml b/bin/embedded_files_test/exec_script/metadata.yml index 18c89da32..8b63acaa1 100644 --- a/bin/embedded_files_test/exec_script/metadata.yml +++ b/bin/embedded_files_test/exec_script/metadata.yml @@ -1,3 +1,4 @@ name: exec_script author: hulto description: Copies a script and executes it. +tactic: UNSPECIFIED diff --git a/bin/embedded_files_test/print/metadata.yml b/bin/embedded_files_test/print/metadata.yml index d60777b89..8973905e4 100644 --- a/bin/embedded_files_test/print/metadata.yml +++ b/bin/embedded_files_test/print/metadata.yml @@ -1,3 +1,4 @@ name: print author: hulto description: It just prints. +tactic: UNSPECIFIED diff --git a/tavern/internal/ent/schema/repository.go b/tavern/internal/ent/schema/repository.go index 230b732f2..19a9246fc 100644 --- a/tavern/internal/ent/schema/repository.go +++ b/tavern/internal/ent/schema/repository.go @@ -109,7 +109,7 @@ func HookCreateRepoPrivateKey() ent.Hook { } // Prepend https schema if no schema specified - if u, ok := mut.URL(); ok && (!strings.HasPrefix(u, "http://") && !strings.HasPrefix(u, "ssh://")) { + if u, ok := mut.URL(); ok && (!strings.HasPrefix(u, "https://") && !strings.HasPrefix(u, "http://") && !strings.HasPrefix(u, "ssh://")) { mut.SetURL(fmt.Sprintf("https://%s", u)) } diff --git a/tavern/internal/graphql/testdata/mutations/createRepository/URLWithHTTPS.yml b/tavern/internal/graphql/testdata/mutations/createRepository/URLWithHTTPS.yml new file mode 100644 index 000000000..ea00386c6 --- /dev/null +++ b/tavern/internal/graphql/testdata/mutations/createRepository/URLWithHTTPS.yml @@ -0,0 +1,24 @@ +state: | + INSERT INTO `users` (id,oauth_id,photo_url,name,session_token,access_token,is_activated,is_admin) + VALUES (5,"test_oauth_id","https://photos.com","test","secretToken","accessToken",true,true); +requestor: + session_token: secretToken +query: | + mutation CreateRepository($input: CreateRepositoryInput!) { + createRepository(input: $input) { + url + + owner { + id + } + } + } +variables: + input: + url: "https://github.com/spellshift/realm" + +expected: + createRepository: + url: "https://github.com/spellshift/realm" + owner: + id: "5" diff --git a/tavern/tomes/git.go b/tavern/tomes/git.go index 71b7cce11..0769ac50b 100644 --- a/tavern/tomes/git.go +++ b/tavern/tomes/git.go @@ -13,6 +13,7 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/filemode" "github.com/go-git/go-git/v5/plumbing/object" + "github.com/go-git/go-git/v5/plumbing/transport" gitssh "github.com/go-git/go-git/v5/plumbing/transport/ssh" "github.com/go-git/go-git/v5/storage/memory" "golang.org/x/crypto/ssh" @@ -53,20 +54,20 @@ type GitImporter struct { // result should be included. func (importer *GitImporter) Import(ctx context.Context, entRepo *ent.Repository, filters ...func(path string) bool) error { // Use Private Key Auth for SSH - var authMethod *gitssh.PublicKeys + var authMethod transport.AuthMethod if strings.HasPrefix(entRepo.URL, "ssh://") { privKey, err := ssh.ParsePrivateKey([]byte(entRepo.PrivateKey)) if err != nil { return fmt.Errorf("failed to parse private key for repository: %w", err) } - authMethod = &gitssh.PublicKeys{ + authMethod = transport.AuthMethod(&gitssh.PublicKeys{ User: "git", Signer: privKey, HostKeyCallbackHelper: gitssh.HostKeyCallbackHelper{ // Ignore Host Keys HostKeyCallback: ssh.InsecureIgnoreHostKey(), }, - } + }) } // Clone Repository (In-Memory) diff --git a/tavern/tomes/parse.go b/tavern/tomes/parse.go index 9a3dab079..232ac8f84 100644 --- a/tavern/tomes/parse.go +++ b/tavern/tomes/parse.go @@ -60,6 +60,9 @@ func (meta MetadataDefinition) Validate() error { if meta.Description == "" { return fmt.Errorf("must set 'description'") } + if meta.Tactic == "" { + return fmt.Errorf("must set 'tactic'") + } for _, paramDef := range meta.ParamDefs { if err := paramDef.Validate(); err != nil { return fmt.Errorf("invalid parameter definition (%q): %w", meta.Name, err)