Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Vault
Commits
92d2d699
Unverified
Commit
92d2d699
authored
4 years ago
by
swayne275
Committed by
GitHub
4 years ago
Browse files
Options
Download
Email Patches
Plain Diff
update oss files with changes from ent PR #1928 (#11965)
parent
8acecaf4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
vault/expiration_test.go
+18
-5
vault/expiration_test.go
vault/expiration_testing_util_common.go
+24
-21
vault/expiration_testing_util_common.go
vault/external_tests/expiration/expiration_test.go
+12
-3
vault/external_tests/expiration/expiration_test.go
with
54 additions
and
29 deletions
+54
-29
vault/expiration_test.go
+
18
-
5
View file @
92d2d699
...
...
@@ -3070,14 +3070,19 @@ func TestExpiration_getIrrevocableLeaseCounts(t *testing.T) {
ns
:
namespace
.
RootNamespace
,
},
}
pathToMount
:=
mountNoopBackends
(
t
,
c
,
backends
)
pathToMount
,
err
:=
mountNoopBackends
(
c
,
backends
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
exp
:=
c
.
expiration
expectedPerMount
:=
10
for
i
:=
0
;
i
<
expectedPerMount
;
i
++
{
for
_
,
backend
:=
range
backends
{
addIrrevocableLease
(
t
,
exp
,
backend
.
path
,
namespace
.
RootNamespace
)
if
_
,
err
:=
c
.
AddIrrevocableLease
(
namespace
.
RootContext
(
nil
),
backend
.
path
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
}
...
...
@@ -3133,7 +3138,10 @@ func TestExpiration_listIrrevocableLeases(t *testing.T) {
ns
:
namespace
.
RootNamespace
,
},
}
pathToMount
:=
mountNoopBackends
(
t
,
c
,
backends
)
pathToMount
,
err
:=
mountNoopBackends
(
c
,
backends
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
exp
:=
c
.
expiration
...
...
@@ -3141,7 +3149,10 @@ func TestExpiration_listIrrevocableLeases(t *testing.T) {
expectedPerMount
:=
10
for
i
:=
0
;
i
<
expectedPerMount
;
i
++
{
for
_
,
backend
:=
range
backends
{
le
:=
addIrrevocableLease
(
t
,
exp
,
backend
.
path
,
namespace
.
RootNamespace
)
le
,
err
:=
c
.
AddIrrevocableLease
(
namespace
.
RootContext
(
nil
),
backend
.
path
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
expectedLeases
=
append
(
expectedLeases
,
&
basicLeaseTestInfo
{
id
:
le
.
id
,
mount
:
pathToMount
[
backend
.
path
],
...
...
@@ -3203,7 +3214,9 @@ func TestExpiration_listIrrevocableLeases_includeAll(t *testing.T) {
expectedNumLeases
:=
MaxIrrevocableLeasesToReturn
+
10
for
i
:=
0
;
i
<
expectedNumLeases
;
i
++
{
addIrrevocableLease
(
t
,
exp
,
"foo/"
,
namespace
.
RootNamespace
)
if
_
,
err
:=
c
.
AddIrrevocableLease
(
namespace
.
RootContext
(
nil
),
"foo/"
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
dataRaw
,
warn
,
err
:=
exp
.
listIrrevocableLeases
(
namespace
.
RootContext
(
nil
),
false
,
false
,
MaxIrrevocableLeasesToReturn
)
...
...
This diff is collapsed.
Click to expand it.
vault/expiration_util_common.go
→
vault/expiration_
testing_
util_common.go
+
24
-
21
View file @
92d2d699
...
...
@@ -5,7 +5,6 @@ import (
"fmt"
"math/rand"
"path"
"testing"
"time"
uuid
"github.com/hashicorp/go-uuid"
...
...
@@ -21,14 +20,18 @@ type basicLeaseTestInfo struct {
// add an irrevocable lease for test purposes
// returns the lease ID and expire time
func
a
ddIrrevocableLease
(
t
*
testing
.
T
,
m
*
ExpirationManager
,
pathPrefix
string
,
ns
*
namespace
.
Namespace
)
*
basicLeaseTestInfo
{
t
.
Helper
()
func
(
c
*
Core
)
A
ddIrrevocableLease
(
ctx
context
.
Context
,
pathPrefix
string
)
(
*
basicLeaseTestInfo
,
error
)
{
exp
:=
c
.
expiration
uuid
,
err
:=
uuid
.
GenerateUUID
()
if
err
!=
nil
{
t
.
Fatal
f
(
"error generating uuid: %
v
"
,
err
)
return
nil
,
fmt
.
Error
f
(
"error generating uuid: %
w
"
,
err
)
}
ns
,
err
:=
namespace
.
FromContext
(
ctx
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error getting namespace from context: %w"
,
err
)
}
if
ns
==
nil
{
ns
=
namespace
.
RootNamespace
}
...
...
@@ -49,28 +52,31 @@ func addIrrevocableLease(t *testing.T, m *ExpirationManager, pathPrefix string,
RevokeErr
:
"some error message"
,
}
m
.
pendingLock
.
Lock
()
defer
m
.
pendingLock
.
Unlock
()
exp
.
pendingLock
.
Lock
()
defer
exp
.
pendingLock
.
Unlock
()
if
err
:=
m
.
persistEntry
(
context
.
Background
(),
le
);
err
!=
nil
{
t
.
Fatal
f
(
"error persisting irrevocable lease: %
v
"
,
err
)
if
err
:=
exp
.
persistEntry
(
context
.
Background
(),
le
);
err
!=
nil
{
return
nil
,
fmt
.
Error
f
(
"error persisting irrevocable lease: %
w
"
,
err
)
}
m
.
updatePendingInternal
(
le
)
exp
.
updatePendingInternal
(
le
)
return
&
basicLeaseTestInfo
{
id
:
le
.
LeaseID
,
expire
:
le
.
ExpireTime
,
}
}
,
nil
}
// InjectIrrevocableLeases injects `count` irrevocable leases (currently to a
// single mount).
// It returns a map of the mount accessor to the number of leases stored there
func
(
c
*
Core
)
InjectIrrevocableLeases
(
t
*
testing
.
T
,
ctx
context
.
Context
,
count
int
)
map
[
string
]
int
{
func
(
c
*
Core
)
InjectIrrevocableLeases
(
ctx
context
.
Context
,
count
int
)
(
map
[
string
]
int
,
error
)
{
out
:=
make
(
map
[
string
]
int
)
for
i
:=
0
;
i
<
count
;
i
++
{
le
:=
addIrrevocableLease
(
t
,
c
.
expiration
,
"foo/"
,
namespace
.
RootNamespace
)
le
,
err
:=
c
.
AddIrrevocableLease
(
ctx
,
"foo/"
)
if
err
!=
nil
{
return
nil
,
err
}
mountAccessor
:=
c
.
expiration
.
getLeaseMountAccessor
(
ctx
,
le
.
id
)
if
_
,
ok
:=
out
[
mountAccessor
];
!
ok
{
...
...
@@ -80,7 +86,7 @@ func (c *Core) InjectIrrevocableLeases(t *testing.T, ctx context.Context, count
out
[
mountAccessor
]
++
}
return
out
return
out
,
nil
}
type
backend
struct
{
...
...
@@ -89,9 +95,7 @@ type backend struct {
}
// set up multiple mounts, and return a mapping of the path to the mount accessor
func
mountNoopBackends
(
t
*
testing
.
T
,
c
*
Core
,
backends
[]
*
backend
)
map
[
string
]
string
{
t
.
Helper
()
func
mountNoopBackends
(
c
*
Core
,
backends
[]
*
backend
)
(
map
[
string
]
string
,
error
)
{
// enable the noop backend
c
.
logicalBackends
[
"noop"
]
=
func
(
ctx
context
.
Context
,
config
*
logical
.
BackendConfig
)
(
logical
.
Backend
,
error
)
{
return
&
NoopBackend
{},
nil
...
...
@@ -106,17 +110,16 @@ func mountNoopBackends(t *testing.T, c *Core, backends []*backend) map[string]st
}
nsCtx
:=
namespace
.
ContextWithNamespace
(
context
.
Background
(),
backend
.
ns
)
err
:=
c
.
mount
(
nsCtx
,
me
)
if
err
!=
nil
{
t
.
Fatalf
(
"err mounting backend %s: %v"
,
backend
.
path
,
err
)
if
err
:=
c
.
mount
(
nsCtx
,
me
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error mounting backend %s: %w"
,
backend
.
path
,
err
)
}
mount
:=
c
.
router
.
MatchingMountEntry
(
nsCtx
,
backend
.
path
)
if
mount
==
nil
{
t
.
Fatal
f
(
"couldn't find mount for path %s"
,
backend
.
path
)
return
nil
,
fmt
.
Error
f
(
"couldn't find mount for path %s"
,
backend
.
path
)
}
pathToMount
[
backend
.
path
]
=
mount
.
Accessor
}
return
pathToMount
return
pathToMount
,
nil
}
This diff is collapsed.
Click to expand it.
vault/external_tests/expiration/expiration_test.go
+
12
-
3
View file @
92d2d699
...
...
@@ -58,7 +58,10 @@ func TestExpiration_irrevocableLeaseCountsAPI(t *testing.T) {
}
expectedNumLeases
:=
50
expectedCountPerMount
:=
core
.
InjectIrrevocableLeases
(
t
,
namespace
.
RootContext
(
nil
),
expectedNumLeases
)
expectedCountPerMount
,
err
:=
core
.
InjectIrrevocableLeases
(
namespace
.
RootContext
(
nil
),
expectedNumLeases
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
resp
,
err
=
client
.
Logical
()
.
ReadWithData
(
"sys/leases/count"
,
params
)
if
err
!=
nil
{
...
...
@@ -162,7 +165,10 @@ func TestExpiration_irrevocableLeaseListAPI(t *testing.T) {
// test with a low enough number to not give an error without limit set to none
expectedNumLeases
:=
50
expectedCountPerMount
:=
core
.
InjectIrrevocableLeases
(
t
,
namespace
.
RootContext
(
nil
),
expectedNumLeases
)
expectedCountPerMount
,
err
:=
core
.
InjectIrrevocableLeases
(
namespace
.
RootContext
(
nil
),
expectedNumLeases
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
resp
,
err
=
client
.
Logical
()
.
ReadWithData
(
"sys/leases"
,
params
)
if
err
!=
nil
{
...
...
@@ -225,7 +231,10 @@ func TestExpiration_irrevocableLeaseListAPI_includeAll(t *testing.T) {
// test with a low enough number to not give an error with the default limit
expectedNumLeases
:=
vault
.
MaxIrrevocableLeasesToReturn
+
50
expectedCountPerMount
:=
core
.
InjectIrrevocableLeases
(
t
,
namespace
.
RootContext
(
nil
),
expectedNumLeases
)
expectedCountPerMount
,
err
:=
core
.
InjectIrrevocableLeases
(
namespace
.
RootContext
(
nil
),
expectedNumLeases
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
params
:=
make
(
map
[
string
][]
string
)
params
[
"type"
]
=
[]
string
{
"irrevocable"
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment