|
| 1 | +package secret_reference |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 6 | + "github.com/aws/aws-sdk-go-v2/config" |
| 7 | + "github.com/aws/aws-sdk-go-v2/credentials" |
| 8 | + "github.com/aws/aws-sdk-go-v2/service/secretsmanager" |
| 9 | + . "github.com/onsi/ginkgo/v2" |
| 10 | + "github.com/onsi/gomega" |
| 11 | + "github.com/stretchr/testify/assert" |
| 12 | + "github.com/webhookx-io/webhookx/app" |
| 13 | + "github.com/webhookx-io/webhookx/test/helper" |
| 14 | + "testing" |
| 15 | +) |
| 16 | + |
| 17 | +var _ = Describe("SecretReference", Ordered, func() { |
| 18 | + |
| 19 | + Context("test", func() { |
| 20 | + var app *app.Application |
| 21 | + |
| 22 | + AfterEach(func() { |
| 23 | + app.Stop() |
| 24 | + }) |
| 25 | + |
| 26 | + BeforeAll(func() { |
| 27 | + helper.InitDB(true, nil) |
| 28 | + // mock aws config |
| 29 | + config, err := config.LoadDefaultConfig(context.TODO(), |
| 30 | + config.WithBaseEndpoint("http://localhost:4566"), |
| 31 | + config.WithRegion("us-east-1"), |
| 32 | + config.WithCredentialsProvider(aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider( |
| 33 | + "test", |
| 34 | + "test", |
| 35 | + "", |
| 36 | + ))), |
| 37 | + ) |
| 38 | + assert.NoError(GinkgoT(), err) |
| 39 | + client := secretsmanager.NewFromConfig(config, func(options *secretsmanager.Options) {}) |
| 40 | + _, err = client.CreateSecret(context.TODO(), &secretsmanager.CreateSecretInput{ |
| 41 | + Name: aws.String("path/to/value"), |
| 42 | + SecretString: aws.String("this is value"), |
| 43 | + }) |
| 44 | + assert.NoError(GinkgoT(), err) |
| 45 | + }) |
| 46 | + |
| 47 | + AfterAll(func() { |
| 48 | + app.Stop() |
| 49 | + }) |
| 50 | + |
| 51 | + It("reference should be de-reference", func() { |
| 52 | + var err error |
| 53 | + app, err = helper.Start(map[string]string{ |
| 54 | + "AWS_ACCESS_KEY_ID": "test", |
| 55 | + "AWS_SECRET_ACCESS_KEY": "test", |
| 56 | + "WEBHOOKX_SECRET_AWS_REGION": "us-east-1", |
| 57 | + "WEBHOOKX_SECRET_AWS_URL": "http://localhost:4566", |
| 58 | + "WEBHOOKX_SECRET_PROVIDER": "aws", |
| 59 | + "WEBHOOKX_REDIS_PASSWORD": "{secret://aws/path/to/value}", |
| 60 | + }) |
| 61 | + assert.Nil(GinkgoT(), err) |
| 62 | + assert.Equal(GinkgoT(), "this is value", string(app.Config().Redis.Password)) |
| 63 | + }) |
| 64 | + }) |
| 65 | + |
| 66 | +}) |
| 67 | + |
| 68 | +func TestAdmin(t *testing.T) { |
| 69 | + gomega.RegisterFailHandler(Fail) |
| 70 | + RunSpecs(t, "SecretReference Suite") |
| 71 | +} |
0 commit comments