Path: blob/dev/pkg/external/customtemplates/github_test.go
2070 views
package customtemplates12import (3"bytes"4"context"5"path/filepath"6"strings"7"testing"89"github.com/projectdiscovery/gologger"10"github.com/projectdiscovery/gologger/levels"11"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"12"github.com/projectdiscovery/nuclei/v3/pkg/testutils"13"github.com/projectdiscovery/nuclei/v3/pkg/utils"14"github.com/stretchr/testify/require"15)1617func TestDownloadCustomTemplatesFromGitHub(t *testing.T) {18// Capture output to check for rate limit errors19outputBuffer := &bytes.Buffer{}20gologger.DefaultLogger.SetWriter(&utils.CaptureWriter{Buffer: outputBuffer})21gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)2223templatesDirectory := t.TempDir()24config.DefaultConfig.SetTemplatesDir(templatesDirectory)2526options := testutils.DefaultOptions27options.GitHubTemplateRepo = []string{"projectdiscovery/nuclei-templates-test"}2829ctm, err := NewCustomTemplatesManager(options)30require.Nil(t, err, "could not create custom templates manager")3132ctm.Download(context.Background())3334// Check if output contains rate limit error and skip test if so35output := outputBuffer.String()36if strings.Contains(output, "API rate limit exceeded") {37t.Skip("GitHub API rate limit exceeded, skipping test")38}3940require.DirExists(t, filepath.Join(templatesDirectory, "github", "projectdiscovery", "nuclei-templates-test"), "cloned directory does not exists")41}424344