|
15 | 15 | package integration
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "fmt" |
| 19 | + "sync" |
18 | 20 | "testing"
|
19 | 21 | "time"
|
20 | 22 |
|
@@ -292,3 +294,41 @@ func TestV3AuthNonAuthorizedRPCs(t *testing.T) {
|
292 | 294 | t.Fatalf("could put key (%v), it should cause an error of permission denied", respput)
|
293 | 295 | }
|
294 | 296 | }
|
| 297 | + |
| 298 | +func TestV3AuthOldRevConcurrent(t *testing.T) { |
| 299 | + defer testutil.AfterTest(t) |
| 300 | + clus := NewClusterV3(t, &ClusterConfig{Size: 1}) |
| 301 | + defer clus.Terminate(t) |
| 302 | + |
| 303 | + authSetupRoot(t, toGRPC(clus.Client(0)).Auth) |
| 304 | + |
| 305 | + c, cerr := clientv3.New(clientv3.Config{ |
| 306 | + Endpoints: clus.Client(0).Endpoints(), |
| 307 | + DialTimeout: 5 * time.Second, |
| 308 | + Username: "root", |
| 309 | + Password: "123", |
| 310 | + }) |
| 311 | + testutil.AssertNil(t, cerr) |
| 312 | + defer c.Close() |
| 313 | + |
| 314 | + var wg sync.WaitGroup |
| 315 | + f := func(i int) { |
| 316 | + defer wg.Done() |
| 317 | + role, user := fmt.Sprintf("test-role-%d", i), fmt.Sprintf("test-user-%d", i) |
| 318 | + _, err := c.RoleAdd(context.TODO(), role) |
| 319 | + testutil.AssertNil(t, err) |
| 320 | + _, err = c.RoleGrantPermission(context.TODO(), role, "", clientv3.GetPrefixRangeEnd(""), clientv3.PermissionType(clientv3.PermReadWrite)) |
| 321 | + testutil.AssertNil(t, err) |
| 322 | + _, err = c.UserAdd(context.TODO(), user, "123") |
| 323 | + testutil.AssertNil(t, err) |
| 324 | + _, err = c.Put(context.TODO(), "a", "b") |
| 325 | + testutil.AssertNil(t, err) |
| 326 | + } |
| 327 | + // needs concurrency to trigger |
| 328 | + numRoles := 2 |
| 329 | + wg.Add(numRoles) |
| 330 | + for i := 0; i < numRoles; i++ { |
| 331 | + go f(i) |
| 332 | + } |
| 333 | + wg.Wait() |
| 334 | +} |
0 commit comments