oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package thin
2
3import (
4 "github.com/spf13/viper"
5 "github.com/zricethezav/gitleaks/v8/config"
6 "github.com/zricethezav/gitleaks/v8/detect"
7 "strings"
8 "testing"
9)
10
11func TestGitHubSecretScan(t *testing.T) {
12 v := viper.New()
13 v.SetConfigType("toml")
14 if err := v.ReadConfig(strings.NewReader(previewSecretRules)); err != nil {
15 t.Fatal(err)
16 }
17 var raw config.ViperConfig
18 if err := v.Unmarshal(&raw); err != nil {
19 t.Fatal(err)
20 }
21 rules, err := raw.Translate()
22 if err != nil {
23 t.Fatal(err)
24 }
25 scanner := detect.NewDetector(rules)
26 scanner.IgnoreGitleaksAllow = true
27 cases := map[string]string{}
28 for _, prefix := range []string{"ghs_", "ghu_", "gho_", "ghr_"} {
29 cases[prefix] = prefix + strings.Repeat("a", 24)
30 }
31 for _, kind := range []string{"", "RSA ", "EC ", "OPENSSH ", "ENCRYPTED "} {
32 cases["PEM "+kind] = "-----BEGIN " + kind + "PRIVATE KEY" + "-----\ntruncated"
33 }
34 for name, secret := range cases {
35 t.Run(name, func(t *testing.T) {
36 if len(scanner.DetectString(secret+" // gitleaks:allow\n")) == 0 {
37 t.Fatal("secret shape admitted")
38 }
39 })
40 }
41}
42