vvauth 2.5.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/gitlab_test.go ADDED
@@ -0,0 +1,116 @@
1
+ package vvauth
2
+
3
+ import (
4
+ "bytes"
5
+ "encoding/json"
6
+ "os"
7
+ "os/exec"
8
+ "path/filepath"
9
+ "strings"
10
+ "testing"
11
+ )
12
+
13
+ func TestGitlabPublishesOnlyProjectVariables(t *testing.T) {
14
+ project := t.TempDir()
15
+ for _, args := range [][]string{{"init", "-q", project}, {"-C", project, "remote", "add", "origin", "ssh://git@git.example.test:2222/Team/sub/App.git"}} {
16
+ if out, err := exec.Command("git", args...).CombinedOutput(); err != nil {
17
+ t.Fatalf("git: %v %s", err, out)
18
+ }
19
+ }
20
+ file := filepath.Join(t.TempDir(), "fixture.vauthrc")
21
+ if err := os.WriteFile(file, []byte(`{"env":{"gitlab":true}}`), 0600); err != nil {
22
+ t.Fatal(err)
23
+ }
24
+ t.Setenv("VAUTHRC", file)
25
+ capture, err := os.Create(filepath.Join(t.TempDir(), "stdout"))
26
+ if err != nil {
27
+ t.Fatal(err)
28
+ }
29
+ stdout := os.Stdout
30
+ os.Stdout = capture
31
+ defer func() { os.Stdout = stdout; capture.Close() }()
32
+ before, err := os.ReadFile(file)
33
+ if err != nil {
34
+ t.Fatal(err)
35
+ }
36
+ cwd, err := os.Getwd()
37
+ if err != nil {
38
+ t.Fatal(err)
39
+ }
40
+ if err := os.Chdir(project); err != nil {
41
+ t.Fatal(err)
42
+ }
43
+ t.Cleanup(func() {
44
+ if err := os.Chdir(cwd); err != nil {
45
+ t.Error(err)
46
+ }
47
+ })
48
+ if err := (&Vauth{}).Gitlab(); err != nil {
49
+ t.Fatal(err)
50
+ }
51
+ if _, err := capture.Seek(0, 0); err != nil {
52
+ t.Fatal(err)
53
+ }
54
+ output := new(bytes.Buffer)
55
+ if _, err := output.ReadFrom(capture); err != nil {
56
+ t.Fatal(err)
57
+ }
58
+ for key, value := range map[string]string{"CI_PROJECT_PATH": "Team/sub/App", "CI_PROJECT_NAME": "App", "CI_PROJECT_NAMESPACE": "Team/sub", "CI_PROJECT_PATH_SLUG": "team-sub-app"} {
59
+ if !strings.Contains(output.String(), "export "+key+"='"+value+"'") {
60
+ t.Fatalf("missing %s", key)
61
+ }
62
+ }
63
+ if strings.Count(output.String(), "\n") != 8 || strings.Contains(output.String(), "VAULT_TOKEN") {
64
+ t.Fatal("unexpected exports")
65
+ }
66
+ after, err := os.ReadFile(file)
67
+ if err != nil {
68
+ t.Fatal(err)
69
+ }
70
+ if !bytes.Equal(before, after) {
71
+ t.Fatal("selected config changed")
72
+ }
73
+ if _, err := os.Stat(filepath.Join(project, ".vauthrc")); !os.IsNotExist(err) {
74
+ t.Fatal("project config created")
75
+ }
76
+ }
77
+
78
+ func TestConstructorGitlabGuardPrecedesAuthentication(t *testing.T) {
79
+ f := newFixture(t, fixtureOptions{})
80
+ file := filepath.Join(t.TempDir(), ".vauthrc")
81
+ document := map[string]any{"vault_addr": f.server.URL, "jwt_auth": map[string]any{"jwt": "test-jwt", "role": "test-role"}, "env": map[string]any{"gitlab": true, "map": map[string]any{"KEEP": "literal"}}}
82
+ body, err := json.Marshal(document)
83
+ if err != nil {
84
+ t.Fatal(err)
85
+ }
86
+ if err := os.WriteFile(file, body, 0600); err != nil {
87
+ t.Fatal(err)
88
+ }
89
+ t.Setenv("VAUTHRC", file)
90
+ t.Setenv("VAULT_TOKEN", "")
91
+ keys := []string{"CI_PROJECT_PATH", "CI_PROJECT_NAME", "CI_PROJECT_NAMESPACE", "CI_PROJECT_PATH_SLUG"}
92
+ for _, key := range keys {
93
+ t.Setenv(key, "")
94
+ }
95
+ if _, err := New(); err == nil || !strings.Contains(err.Error(), "Run venv --gitlab first") {
96
+ t.Fatal("constructor accepted missing vars")
97
+ }
98
+ equal(t, len(f.requests), 0)
99
+ for _, key := range keys {
100
+ t.Setenv(key, "provided")
101
+ }
102
+ v, err := New()
103
+ if err != nil {
104
+ t.Fatal(err)
105
+ }
106
+ v.TokenCache = false
107
+ env, err := v.Env(false)
108
+ if err != nil {
109
+ t.Fatal(err)
110
+ }
111
+ value, _ := env.Get("KEEP")
112
+ equal(t, value, "literal")
113
+ if len(f.requests) == 0 {
114
+ t.Fatal("normal auth not performed after initialization")
115
+ }
116
+ }
package/go.mod CHANGED
@@ -1,16 +1,19 @@
1
1
  module github.com/131/vvauth/v2
2
2
 
3
- // version: 2.5.0
3
+ // version: 2.6.1
4
4
 
5
5
  go 1.22
6
6
 
7
7
  require (
8
- github.com/131/ssh-agent-crypt v1.3.3
9
- golang.org/x/crypto v0.31.0
8
+ github.com/131/ssh-agent-crypt v1.4.4
9
+ github.com/131/vauth-login v1.1.7
10
+ github.com/Masterminds/semver/v3 v3.5.0
10
11
  gopkg.in/yaml.v3 v3.0.1
11
12
  )
12
13
 
13
14
  require (
15
+ github.com/131/nyks/v6 v6.18.0
14
16
  github.com/Microsoft/go-winio v0.6.2 // indirect
17
+ golang.org/x/crypto v0.31.0 // indirect
15
18
  golang.org/x/sys v0.28.0 // indirect
16
19
  )
package/go.sum CHANGED
@@ -1,5 +1,11 @@
1
- github.com/131/ssh-agent-crypt v1.3.3 h1:+sITI4C55Ck5Kype/aKcn/6MoGeCfk9GshogF0LZgkI=
2
- github.com/131/ssh-agent-crypt v1.3.3/go.mod h1:XNiI2n3+2NTwjhyd/plFhrd0vSfWOZ58ocvqTlx1Ydk=
1
+ github.com/131/nyks/v6 v6.18.0 h1:xpjRJk2YAyoqqgSvWrox0eIGZ1AY4IkEvqETavcwcQk=
2
+ github.com/131/nyks/v6 v6.18.0/go.mod h1:ckNI5ql4USp+kQyrG1c35tl/PrPSgpoNXktcnQGJpdk=
3
+ github.com/131/ssh-agent-crypt v1.4.4 h1:6MlDUao1Yq6iNY4Bgin/iZp2q3X/g6qD6H1X4ad8ukY=
4
+ github.com/131/ssh-agent-crypt v1.4.4/go.mod h1:/THxpIdVrEAHxNoc6t6lVYBsSEd1zkCROPZepDe8QTI=
5
+ github.com/131/vauth-login v1.1.7 h1:i256JyHP05WKqIrLv18ThfitGipH4oKnN7zpQESzV7U=
6
+ github.com/131/vauth-login v1.1.7/go.mod h1:Dch6CZkaAxnYCD1V83h0g0xPQORjQoZarOOVt4mhNv8=
7
+ github.com/Masterminds/semver/v3 v3.5.0 h1:kQceYJfbupGfZOKZQg0kou0DgAKhzDg2NZPAwZ/2OOE=
8
+ github.com/Masterminds/semver/v3 v3.5.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
3
9
  github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
4
10
  github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
5
11
  golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=