* private key analyzer initial impl - basic structure * Impl analyzePermission method for PrivateKey analyzer. export few private functions for reusability in analyzers * add permissions.yaml and generate permissions * permissions fix * AnalyzeAndPrintPermissions impl * analyzer test pushed * Impl analyzer func called from detector. added and regenerated permissions. * filter empty strings in result and generate expected_output for test * some refactoring * comment added for better readability. * fixed code breaking changes in detectors due to exporting private functions. * log insufficient information message on no certificate results
39 lines
840 B
Go
39 lines
840 B
Go
//go:build detectors
|
|
// +build detectors
|
|
|
|
package privatekey
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
|
|
)
|
|
|
|
func TestFirstResponseFromSSH(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
|
defer cancel()
|
|
testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors4")
|
|
if err != nil {
|
|
t.Fatalf("could not get test secrets from GCP: %s", err)
|
|
}
|
|
secretGitHub := testSecrets.MustGetField("PRIVATEKEY_GITHUB")
|
|
|
|
parsedKey, err := ssh.ParseRawPrivateKey([]byte(Normalize(secretGitHub)))
|
|
if err != nil {
|
|
t.Fatalf("could not parse test secret: %s", err)
|
|
}
|
|
|
|
output, err := firstResponseFromSSH(ctx, parsedKey, "git", "github.com:22")
|
|
if err != nil {
|
|
t.Fail()
|
|
}
|
|
|
|
if len(output) == 0 {
|
|
t.Fail()
|
|
}
|
|
}
|