Skip to content

Commit ece9cc6

Browse files
committed
Merge commit '7e891607bdc09f4c20d713d09a04c2950795de57' into anemone-merge
2 parents f2939ae + 7e89160 commit ece9cc6

File tree

69 files changed

+1461
-495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1461
-495
lines changed

.golangci-strict.yml

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,36 @@ linters:
3434
#- unparam # Reports unused function parameters
3535
- unused # (megacheck) Checks Go code for unused constants, variables, functions and types
3636
disable:
37-
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
38-
- depguard # Go linter that checks if package imports are in a list of acceptable packages
39-
- dogsled # Checks assignments with too many blank identifiers # (e.g. x, _, _, _, := f())
40-
- err113 # Golang linter to check the errors handling expressions
41-
- funlen # Tool for detection of long functions
42-
- gochecknoglobals # Checks that no globals are present in Go code
43-
- gochecknoinits # Checks that no init functions are present in Go code
44-
- gocognit # Computes and checks the cognitive complexity of functions
45-
- gocyclo # Computes and checks the cyclomatic complexity of functions
46-
- godot # Check if comments end in a period
47-
- godox # Tool for detection of FIXME, TODO and other comment keywords
48-
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
49-
- gomodguard # Allow and block list linter for direct Go module dependencies.
50-
- lll # Reports long lines
51-
- nestif # Reports deeply nested if statements
52-
- nolintlint # Reports ill-formed or insufficient nolint directives
53-
- rowserrcheck # checks whether Err of rows is checked successfully
54-
- stylecheck # Stylecheck is a replacement for golint
55-
- testpackage # linter that makes you use a separate _test package
56-
- whitespace # Tool for detection of leading and trailing whitespace
57-
- wsl # Whitespace Linter - Forces you to use empty lines!
37+
# - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
38+
# - depguard # Go linter that checks if package imports are in a list of acceptable packages
39+
# - dogsled # Checks assignments with too many blank identifiers # (e.g. x, _, _, _, := f())
40+
# - err113 # Golang linter to check the errors handling expressions
41+
# - funlen # Tool for detection of long functions
42+
# - gochecknoglobals # Checks that no globals are present in Go code
43+
# - gochecknoinits # Checks that no init functions are present in Go code
44+
# - gocognit # Computes and checks the cognitive complexity of functions
45+
# - gocyclo # Computes and checks the cyclomatic complexity of functions
46+
# - godot # Check if comments end in a period
47+
# - godox # Tool for detection of FIXME, TODO and other comment keywords
48+
# - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
49+
# - gomodguard # Allow and block list linter for direct Go module dependencies.
50+
# - lll # Reports long lines
51+
# - nestif # Reports deeply nested if statements
52+
# - rowserrcheck # checks whether Err of rows is checked successfully
53+
# - stylecheck # Stylecheck is a replacement for golint
54+
# - testpackage # linter that makes you use a separate _test package
55+
# - whitespace # Tool for detection of leading and trailing whitespace
56+
# - wsl # Whitespace Linter - Forces you to use empty lines!
5857
# Once fixed, should enable
59-
- dupl # Tool for code clone detection
60-
- goconst # Finds repeated strings that could be replaced by a constant
61-
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
62-
- gosec # (gas) Inspects source code for security problems
58+
# - dupl # Tool for code clone detection
59+
# - goconst # Finds repeated strings that could be replaced by a constant
60+
# - goprintffuncname # Checks that printf-like functions are named with `f` at the end
61+
# - gosec # (gas) Inspects source code for security problems
6362
- gosimple # (megacheck) Linter for Go source code that specializes in simplifying a code
64-
- nakedret # Finds naked returns in functions greater than a specified function length
65-
- prealloc # Finds slice declarations that could potentially be preallocated
66-
- revive # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
67-
- unparam # Reports unused function parameters
63+
# - nakedret # Finds naked returns in functions greater than a specified function length
64+
# - prealloc # Finds slice declarations that could potentially be preallocated
65+
# - revive # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
66+
# - unparam # Reports unused function parameters
6867

6968
# Don't enable fieldalignment, changing the field alignment requires checking to see if anyone uses constructors
7069
# without names. If there is a memory issue on a specific field, that is best found with a heap profile.
@@ -76,7 +75,9 @@ linters:
7675
# Disable goconst in test files, often we have duplicated strings across tests, but don't make sense as constants.
7776
issues:
7877
exclude-rules:
79-
- path: (_test\.go|utilities_testing\.go)
78+
# cover _testing.go (utility testing files) and _test.go files
79+
# base/util_testing.go / rest/utilities_testing\.*.go
80+
- path: (_test.*\.go)
8081
linters:
8182
- goconst
8283
- path: rest/debug.go
@@ -104,4 +105,5 @@ linters-settings:
104105
- wrapperFunc
105106
settings:
106107
ruleguard:
107-
rules: '${configDir}/ruleguard/*.go'
108+
rules: '${configDir}/ruleguard/rules-*.go'
109+
failOn: all

.golangci.yml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,27 @@ linters:
3333
- unconvert # Remove unnecessary type conversions
3434
- unparam # Reports unused function parameters
3535
- unused # (megacheck) Checks Go code for unused constants, variables, functions and types
36-
disable:
37-
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
38-
- depguard # Go linter that checks if package imports are in a list of acceptable packages
39-
- dogsled # Checks assignments with too many blank identifiers # (e.g. x, _, _, _, := f())
40-
- err113 # Golang linter to check the errors handling expressions
41-
- funlen # Tool for detection of long functions
42-
- gochecknoglobals # Checks that no globals are present in Go code
43-
- gochecknoinits # Checks that no init functions are present in Go code
44-
- gocognit # Computes and checks the cognitive complexity of functions
45-
- gocyclo # Computes and checks the cyclomatic complexity of functions
46-
- godot # Check if comments end in a period
47-
- godox # Tool for detection of FIXME, TODO and other comment keywords
48-
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
49-
- gomodguard # Allow and block list linter for direct Go module dependencies.
50-
- lll # Reports long lines
51-
- nestif # Reports deeply nested if statements
52-
- nolintlint # Reports ill-formed or insufficient nolint directives
53-
- rowserrcheck # checks whether Err of rows is checked successfully
54-
- stylecheck # Stylecheck is a replacement for golint
55-
- testpackage # linter that makes you use a separate _test package
56-
- whitespace # Tool for detection of leading and trailing whitespace
57-
- wsl # Whitespace Linter - Forces you to use empty lines!
36+
# disable:
37+
# - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
38+
# - depguard # Go linter that checks if package imports are in a list of acceptable packages
39+
# - dogsled # Checks assignments with too many blank identifiers # (e.g. x, _, _, _, := f())
40+
# - err113 # Golang linter to check the errors handling expressions
41+
# - funlen # Tool for detection of long functions
42+
# - gochecknoglobals # Checks that no globals are present in Go code
43+
# - gochecknoinits # Checks that no init functions are present in Go code
44+
# - gocognit # Computes and checks the cognitive complexity of functions
45+
# - gocyclo # Computes and checks the cyclomatic complexity of functions
46+
# - godot # Check if comments end in a period
47+
# - godox # Tool for detection of FIXME, TODO and other comment keywords
48+
# - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
49+
# - gomodguard # Allow and block list linter for direct Go module dependencies.
50+
# - lll # Reports long lines
51+
# - nestif # Reports deeply nested if statements
52+
# - rowserrcheck # checks whether Err of rows is checked successfully
53+
# - stylecheck # Stylecheck is a replacement for golint
54+
# - testpackage # linter that makes you use a separate _test package
55+
# - whitespace # Tool for detection of leading and trailing whitespace
56+
# - wsl # Whitespace Linter - Forces you to use empty lines!
5857

5958
linters-settings:
6059
govet:
@@ -65,16 +64,19 @@ linters-settings:
6564
- ruleguard
6665
settings:
6766
ruleguard:
68-
rules: '${configDir}/ruleguard/*.go'
67+
rules: '${configDir}/ruleguard/rules-*.go'
68+
failOn: all
6969

7070
# Disable goconst in test files, often we have duplicated strings across tests, but don't make sense as constants.
7171
issues:
7272
exclude-rules:
73-
- path: (_test\.go|utilities_testing\.go)
73+
# cover _testing.go (utility testing files) and _test.go files
74+
# base/util_testing.go / rest/utilities_testing\.*.go
75+
- path: (_test.*\.go)
7476
linters:
7577
- goconst
7678
- prealloc
77-
- path: (_test\.go|utilities_testing\.go)
79+
- path: (_test.*\.go)
7880
linters:
7981
- govet
8082
text: fieldalignment

auth/auth.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ func (auth *Authenticator) UpdateUserEmail(u User, email string) error {
631631
if err != nil {
632632
return nil, err
633633
}
634+
currentUser.SetUpdatedAt()
635+
634636
return currentUser, nil
635637
}
636638

@@ -662,6 +664,7 @@ func (auth *Authenticator) rehashPassword(user User, password string) error {
662664
if err != nil {
663665
return nil, err
664666
}
667+
currentUserImpl.SetUpdatedAt()
665668
return currentUserImpl, nil
666669
} else {
667670
return nil, base.ErrUpdateCancel
@@ -740,6 +743,7 @@ func (auth *Authenticator) DeleteRole(role Role, purge bool, deleteSeq uint64) e
740743
}
741744
p.setDeleted(true)
742745
p.SetSequence(deleteSeq)
746+
p.SetUpdatedAt()
743747

744748
// Update channel history for default collection
745749
channelHistory := auth.calculateHistory(p.Name(), deleteSeq, p.Channels(), nil, p.ChannelHistory())
@@ -955,6 +959,8 @@ func (auth *Authenticator) RegisterNewUser(username, email string) (User, error)
955959
base.WarnfCtx(auth.LogCtx, "Skipping SetEmail for user %q - Invalid email address provided: %q", base.UD(username), base.UD(email))
956960
}
957961
}
962+
user.SetUpdatedAt()
963+
user.SetCreatedAt(time.Now().UTC())
958964

959965
err = auth.Save(user)
960966
if base.IsCasMismatch(err) {

auth/principal.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ type Principal interface {
5252
setDeleted(bool)
5353
IsDeleted() bool
5454

55+
// Sets the updated time for the principal document
56+
SetUpdatedAt()
57+
58+
// Sets the created time for the principal document
59+
SetCreatedAt(t time.Time)
60+
5561
// Principal includes the PrincipalCollectionAccess interface for operations against
5662
// the _default._default collection (stored directly on the principal for backward
5763
// compatibility)

auth/role.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type roleImpl struct {
3333
ChannelInvalSeq uint64 `json:"channel_inval_seq,omitempty"` // Sequence at which the channels were invalidated. Data remains in Channels_ for history calculation.
3434
Deleted bool `json:"deleted,omitempty"`
3535
CollectionsAccess map[string]map[string]*CollectionAccess `json:"collection_access,omitempty"` // Nested maps of CollectionAccess, indexed by scope and collection name
36+
UpdatedAt time.Time `json:"updated_at"`
37+
CreatedAt time.Time `json:"created_at"`
3638
cas uint64
3739
docID string // key used to store the roleImpl
3840
}
@@ -277,6 +279,14 @@ func (role *roleImpl) Name() string {
277279
return role.Name_
278280
}
279281

282+
func (role *roleImpl) SetUpdatedAt() {
283+
role.UpdatedAt = time.Now().UTC()
284+
}
285+
286+
func (role *roleImpl) SetCreatedAt(t time.Time) {
287+
role.CreatedAt = t
288+
}
289+
280290
func (role *roleImpl) Sequence() uint64 {
281291
return role.Sequence_
282292
}

base/collection_xattr_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,11 +1324,8 @@ func TestWriteWithXattrsInsertAndDeleteError(t *testing.T) {
13241324
func requireXattrsEqual(t testing.TB, expected map[string][]byte, actual map[string][]byte) {
13251325
require.Len(t, actual, len(expected), "Expected xattrs to be the same length %v, got %v", expected, actual)
13261326
for k, v := range expected {
1327-
actualV, ok := actual[k]
1328-
if !ok {
1329-
require.Fail(t, "Missing expected xattr %s", k)
1330-
}
1331-
require.JSONEq(t, string(v), string(actualV))
1327+
require.Contains(t, actual, k)
1328+
require.JSONEq(t, string(v), string(actual[k]))
13321329
}
13331330
}
13341331

base/dcp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func TestConcurrentCBGTIndexCreation(t *testing.T) {
466466
case <-terminatorChan:
467467
context.Manager.Stop()
468468
case <-time.After(20 * time.Second):
469-
assert.Fail(t, "manager goroutine not terminated: %v", managerUUID)
469+
require.Fail(t, fmt.Sprintf("manager goroutine not terminated: %v", managerUUID))
470470
}
471471

472472
}(i, terminator)

base/leaky_bucket.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ type LeakyBucketConfig struct {
125125

126126
// Returns a partial error the first time ViewCustom is called
127127
FirstTimeViewCustomPartialError bool
128-
PostQueryCallback func(ddoc, viewName string, params map[string]interface{}) // Issues callback after issuing query when bucket.ViewQuery is called
128+
129+
// QueryCallback allows tests to set a callback that will be issued prior to issuing a view query
130+
QueryCallback func(ddoc, viewName string, params map[string]any) error
131+
PostQueryCallback func(ddoc, viewName string, params map[string]interface{}) // Issues callback after issuing query when bucket.ViewQuery is called
132+
133+
N1QLQueryCallback func(ctx context.Context, statement string, params map[string]any, consistency ConsistencyMode, adhoc bool) error
129134

130135
PostN1QLQueryCallback func()
131136

base/leaky_datastore.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ func (lds *LeakyDataStore) ViewQuery(ctx context.Context, ddoc, name string, par
241241
if !ok {
242242
return nil, errors.New("bucket does not support views")
243243
}
244+
if lds.config.QueryCallback != nil {
245+
err := lds.config.QueryCallback(ddoc, name, params)
246+
if err != nil {
247+
return nil, err
248+
}
249+
}
244250
iterator, err := vs.ViewQuery(ctx, ddoc, name, params)
245251

246252
if lds.config.FirstTimeViewCustomPartialError {
@@ -324,10 +330,14 @@ func (lds *LeakyDataStore) SetFirstTimeViewCustomPartialError(val bool) {
324330
lds.config.FirstTimeViewCustomPartialError = val
325331
}
326332

327-
func (lds *LeakyDataStore) SetPostQueryCallback(callback func(ddoc, viewName string, params map[string]interface{})) {
333+
func (lds *LeakyDataStore) SetPostQueryCallback(callback func(ddoc, viewName string, params map[string]any)) {
328334
lds.config.PostQueryCallback = callback
329335
}
330336

337+
func (lds *LeakyDataStore) SetQueryCallback(fn func(ddoc, viewName string, params map[string]any) error) {
338+
lds.config.QueryCallback = fn
339+
}
340+
331341
func (lds *LeakyDataStore) SetPostN1QLQueryCallback(callback func()) {
332342
lds.config.PostN1QLQueryCallback = callback
333343
}
@@ -447,6 +457,12 @@ func (lds *LeakyDataStore) Query(ctx context.Context, statement string, params m
447457
if err != nil {
448458
return nil, err
449459
}
460+
if lds.config.N1QLQueryCallback != nil {
461+
err := lds.config.N1QLQueryCallback(ctx, statement, params, consistency, adhoc)
462+
if err != nil {
463+
return nil, err
464+
}
465+
}
450466
iterator, err := n1qlStore.Query(ctx, statement, params, consistency, adhoc)
451467

452468
if lds.config.PostN1QLQueryCallback != nil {

base/main_test_bucket_pool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func NewTestBucketPoolWithOptions(ctx context.Context, bucketReadierFunc TBPBuck
121121
unclosedBuckets: make(map[string]map[string]struct{}),
122122
useExistingBucket: TestUseExistingBucket(),
123123
useDefaultScope: options.UseDefaultScope,
124+
skipMobileXDCR: true, // do not set up enableCrossClusterVersioning until Sync Gateway 4.x
124125
}
125126

126127
tbp.cluster = newTestCluster(ctx, UnitTestUrl(), &tbp)

0 commit comments

Comments
 (0)