nuclei/pkg/installer/template_test.go
Dwi Siswanto 87ed0b2bb9
build: bump all direct modules (#6290)
* chore: fix non-constant fmt string in call

Signed-off-by: Dwi Siswanto <git@dw1.io>

* build: bump all direct modules

Signed-off-by: Dwi Siswanto <git@dw1.io>

* chore(hosterrorscache): update import path

Signed-off-by: Dwi Siswanto <git@dw1.io>

* fix(charts): break changes

Signed-off-by: Dwi Siswanto <git@dw1.io>

* build: pinned `github.com/zmap/zcrypto` to v0.0.0-20240512203510-0fef58d9a9db

Signed-off-by: Dwi Siswanto <git@dw1.io>

* chore: golangci-lint auto fixes

Signed-off-by: Dwi Siswanto <git@dw1.io>

* chore: satisfy lints

Signed-off-by: Dwi Siswanto <git@dw1.io>

* build: migrate `github.com/xanzy/go-gitlab` => `gitlab.com/gitlab-org/api/client-go`

Signed-off-by: Dwi Siswanto <git@dw1.io>

* feat(json): update build constraints

Signed-off-by: Dwi Siswanto <git@dw1.io>

* chore: dont panicking on close err

Signed-off-by: Dwi Siswanto <git@dw1.io>

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-07-01 00:40:44 +07:00

62 lines
1.6 KiB
Go

package installer
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
"github.com/stretchr/testify/require"
)
func TestTemplateInstallation(t *testing.T) {
// test that the templates are installed correctly
// along with necessary changes that are made
HideProgressBar = true
tm := &TemplateManager{}
dir, err := os.MkdirTemp("", "nuclei-templates-*")
require.Nil(t, err)
cfgdir, err := os.MkdirTemp("", "nuclei-config-*")
require.Nil(t, err)
defer func() {
_ = os.RemoveAll(dir)
_ = os.RemoveAll(cfgdir)
}()
// set the config directory to a temporary directory
config.DefaultConfig.SetConfigDir(cfgdir)
// set the templates directory to a temporary directory
templatesTempDir := filepath.Join(dir, "templates")
config.DefaultConfig.SetTemplatesDir(templatesTempDir)
err = tm.FreshInstallIfNotExists()
if err != nil {
if strings.Contains(err.Error(), "rate limit") {
t.Skip("Skipping test due to github rate limit")
}
require.Nil(t, err)
}
// we should switch to more fine granular tests for template
// integrity, but for now, we just check that the templates are installed
counter := 0
err = filepath.Walk(templatesTempDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
counter++
}
return nil
})
require.Nil(t, err)
// we should have at least 1000 templates
require.Greater(t, counter, 1000)
// every time we install templates, it should override the ignore file with latest one
require.FileExists(t, config.DefaultConfig.GetIgnoreFilePath())
t.Logf("Installed %d templates", counter)
}