Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/external/customtemplates/github_test.go
2070 views
1
package customtemplates
2
3
import (
4
"bytes"
5
"context"
6
"path/filepath"
7
"strings"
8
"testing"
9
10
"github.com/projectdiscovery/gologger"
11
"github.com/projectdiscovery/gologger/levels"
12
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
13
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
14
"github.com/projectdiscovery/nuclei/v3/pkg/utils"
15
"github.com/stretchr/testify/require"
16
)
17
18
func TestDownloadCustomTemplatesFromGitHub(t *testing.T) {
19
// Capture output to check for rate limit errors
20
outputBuffer := &bytes.Buffer{}
21
gologger.DefaultLogger.SetWriter(&utils.CaptureWriter{Buffer: outputBuffer})
22
gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
23
24
templatesDirectory := t.TempDir()
25
config.DefaultConfig.SetTemplatesDir(templatesDirectory)
26
27
options := testutils.DefaultOptions
28
options.GitHubTemplateRepo = []string{"projectdiscovery/nuclei-templates-test"}
29
30
ctm, err := NewCustomTemplatesManager(options)
31
require.Nil(t, err, "could not create custom templates manager")
32
33
ctm.Download(context.Background())
34
35
// Check if output contains rate limit error and skip test if so
36
output := outputBuffer.String()
37
if strings.Contains(output, "API rate limit exceeded") {
38
t.Skip("GitHub API rate limit exceeded, skipping test")
39
}
40
41
require.DirExists(t, filepath.Join(templatesDirectory, "github", "projectdiscovery", "nuclei-templates-test"), "cloned directory does not exists")
42
}
43
44