@@ -16,6 +16,8 @@ import (
16
16
"github.com/hashicorp/vault/helper/namespace"
17
17
"github.com/hashicorp/vault/sdk/framework"
18
18
"github.com/hashicorp/vault/sdk/logical"
19
+ "github.com/hashicorp/vault/version"
20
+ "google.golang.org/protobuf/types/known/timestamppb"
19
21
)
20
22
21
23
var (
@@ -286,6 +288,50 @@ func TestDynamicSystemView_GeneratePasswordFromPolicy_failed(t *testing.T) {
286
288
}
287
289
}
288
290
291
+ // TestDynamicSystemView_PluginEnv_successful checks that the PluginEnv method returns the expected values in a successful case.
292
+ func TestDynamicSystemView_PluginEnv_successful (t * testing.T ) {
293
+ coreConfig := & CoreConfig {
294
+ CredentialBackends : map [string ]logical.Factory {},
295
+ }
296
+
297
+ cluster := NewTestCluster (t , coreConfig , & TestClusterOptions {})
298
+
299
+ cluster .Start ()
300
+ defer cluster .Cleanup ()
301
+
302
+ core := cluster .Cores [0 ].Core
303
+ TestWaitActive (t , core )
304
+
305
+ ctx , cancel := context .WithTimeout (context .Background (), 1 * time .Second )
306
+ defer cancel ()
307
+
308
+ ctx = namespace .RootContext (ctx )
309
+ dsv := TestDynamicSystemView (cluster .Cores [0 ].Core , nil )
310
+
311
+ pluginEnv , err := dsv .PluginEnv (ctx )
312
+ if err != nil {
313
+ t .Fatalf ("no error expected, but got: %s" , err )
314
+ }
315
+
316
+ expectedVersionInfo := version .GetVersion ()
317
+
318
+ expectedBuildDate , err := version .GetVaultBuildDate ()
319
+ if err != nil {
320
+ t .Fatalf ("failed to set up expectedBuildDate: %v" , err )
321
+ }
322
+
323
+ expectedPluginEnv := & logical.PluginEnvironment {
324
+ VaultVersion : expectedVersionInfo .Version ,
325
+ VaultVersionPrerelease : expectedVersionInfo .VersionPrerelease ,
326
+ VaultVersionMetadata : expectedVersionInfo .VersionMetadata ,
327
+ VaultBuildDate : timestamppb .New (expectedBuildDate ),
328
+ }
329
+
330
+ if ! reflect .DeepEqual (pluginEnv , expectedPluginEnv ) {
331
+ t .Fatalf ("got %q, expected %q" , pluginEnv , expectedPluginEnv )
332
+ }
333
+ }
334
+
289
335
type runes []rune
290
336
291
337
func (r runes ) Len () int { return len (r ) }
0 commit comments