-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fdd282
commit b639d8e
Showing
18 changed files
with
312 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package config_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Kuma DP Config Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package config | ||
|
||
import ( | ||
util_files "github.com/Kong/kuma/pkg/util/files" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func ValidateTokenPath(path string) error { | ||
if path == "" { | ||
return nil | ||
} | ||
empty, err := util_files.FileEmpty(path) | ||
if err != nil { | ||
return errors.Wrap(err, "could not read file") | ||
} | ||
if empty { | ||
return errors.Errorf("token under file %s is empty", path) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package config_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Kong/kuma/app/kuma-dp/pkg/config" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
var _ = Describe("ValidateTokenPath", func() { | ||
|
||
var tokenFile *os.File | ||
|
||
BeforeEach(func() { | ||
tf, err := ioutil.TempFile("", "") | ||
Expect(err).ToNot(HaveOccurred()) | ||
tokenFile = tf | ||
}) | ||
|
||
It("should pass validation for empty path", func() { | ||
// when | ||
err := config.ValidateTokenPath("") | ||
|
||
// then | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("should pass validation for empty path", func() { | ||
// given | ||
_, err := tokenFile.WriteString("sampletoken") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// when | ||
err = config.ValidateTokenPath("") | ||
|
||
// then | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("should fail for non existing file", func() { | ||
// when | ||
err := config.ValidateTokenPath("nonexistingfile") | ||
|
||
// then | ||
Expect(err).To(MatchError("could not read file: stat nonexistingfile: no such file or directory")) | ||
}) | ||
|
||
It("should fail for empty file", func() { | ||
// when | ||
err := config.ValidateTokenPath(tokenFile.Name()) | ||
|
||
// then | ||
Expect(err).To(MatchError(fmt.Sprintf("token under file %s is empty", tokenFile.Name()))) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package files | ||
|
||
import "os" | ||
|
||
func FileExists(path string) bool { | ||
_, err := os.Stat(path) | ||
return err == nil | ||
} | ||
|
||
func FileEmpty(path string) (bool, error) { | ||
file, err := os.Stat(path) | ||
if err != nil { | ||
return true, err | ||
} | ||
return file.Size() == 0, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
pkg/xds/bootstrap/testdata/generator.custom-config-minimal-request.golden.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
admin: | ||
accessLogPath: /var/log | ||
address: | ||
socketAddress: | ||
address: 192.168.0.1 | ||
portValue: 9902 | ||
dynamicResources: | ||
adsConfig: | ||
apiType: GRPC | ||
grpcServices: | ||
- envoyGrpc: | ||
clusterName: ads_cluster | ||
cdsConfig: | ||
ads: {} | ||
ldsConfig: | ||
ads: {} | ||
node: | ||
cluster: backend | ||
id: mesh.name.namespace | ||
staticResources: | ||
clusters: | ||
- connectTimeout: 2s | ||
http2ProtocolOptions: {} | ||
loadAssignment: | ||
clusterName: ads_cluster | ||
endpoints: | ||
- lbEndpoints: | ||
- endpoint: | ||
address: | ||
socketAddress: | ||
address: kuma-control-plane.internal | ||
portValue: 15678 | ||
name: ads_cluster | ||
type: STRICT_DNS | ||
upstreamConnectionOptions: | ||
tcpKeepalive: {} | ||
- connectTimeout: 2s | ||
http2ProtocolOptions: {} | ||
loadAssignment: | ||
clusterName: access_log_sink | ||
endpoints: | ||
- lbEndpoints: | ||
- endpoint: | ||
address: | ||
pipe: | ||
path: /tmp/kuma-access-logs-name.namespace-mesh.sock | ||
name: access_log_sink | ||
type: STATIC | ||
upstreamConnectionOptions: | ||
tcpKeepalive: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
pkg/xds/bootstrap/testdata/generator.default-config-minimal-request.golden.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
dynamicResources: | ||
adsConfig: | ||
apiType: GRPC | ||
grpcServices: | ||
- envoyGrpc: | ||
clusterName: ads_cluster | ||
cdsConfig: | ||
ads: {} | ||
ldsConfig: | ||
ads: {} | ||
node: | ||
cluster: backend | ||
id: mesh.name.namespace | ||
staticResources: | ||
clusters: | ||
- connectTimeout: 1s | ||
http2ProtocolOptions: {} | ||
loadAssignment: | ||
clusterName: ads_cluster | ||
endpoints: | ||
- lbEndpoints: | ||
- endpoint: | ||
address: | ||
socketAddress: | ||
address: 127.0.0.1 | ||
portValue: 5678 | ||
name: ads_cluster | ||
type: STRICT_DNS | ||
upstreamConnectionOptions: | ||
tcpKeepalive: {} | ||
- connectTimeout: 1s | ||
http2ProtocolOptions: {} | ||
loadAssignment: | ||
clusterName: access_log_sink | ||
endpoints: | ||
- lbEndpoints: | ||
- endpoint: | ||
address: | ||
pipe: | ||
path: /tmp/kuma-access-logs-name.namespace-mesh.sock | ||
name: access_log_sink | ||
type: STATIC | ||
upstreamConnectionOptions: | ||
tcpKeepalive: {} |
6 changes: 6 additions & 0 deletions
6
pkg/xds/bootstrap/testdata/generator.default-config.golden.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.