Test for https://issues.redhat.com/browse/EC-936, where we had multiple symbolic links pointing to the same policy download within the same workdir causing Rego compile issue
(t *testing.T)
| 603 | // symbolic links pointing to the same policy download within the same workdir |
| 604 | // causing Rego compile issue |
| 605 | func TestDownloadCacheWorkdirMismatch(t *testing.T) { |
| 606 | t.Cleanup(func() { |
| 607 | downloadCache = sync.Map{} |
| 608 | }) |
| 609 | tmp := t.TempDir() |
| 610 | |
| 611 | source := &mockPolicySource{&mock.Mock{}} |
| 612 | source.On("PolicyUrl").Return("policy-url") |
| 613 | source.On("Subdir").Return("subdir") |
| 614 | |
| 615 | // same URL downloaded to workdir1 |
| 616 | precachedDest := uniqueDestination(tmp, "subdir", source.PolicyUrl()) |
| 617 | require.NoError(t, os.MkdirAll(precachedDest, 0o755)) |
| 618 | downloadCache.Store("policy-url", func() (string, cacheContent) { |
| 619 | return precachedDest, cacheContent{} |
| 620 | }) |
| 621 | |
| 622 | // when working in workdir2 |
| 623 | workdir2 := filepath.Join(tmp, "workdir2") |
| 624 | |
| 625 | // first invocation symlinks back to workdir1 |
| 626 | destination1, _, err := getPolicyThroughCache(context.Background(), source, workdir2, func(s1, s2 string) (metadata.Metadata, error) { return nil, nil }) |
| 627 | require.NoError(t, err) |
| 628 | |
| 629 | // second invocation should not create a second symlink and duplicate the |
| 630 | // source files within workdir2 |
| 631 | destination2, _, err := getPolicyThroughCache(context.Background(), source, workdir2, func(s1, s2 string) (metadata.Metadata, error) { return nil, nil }) |
| 632 | require.NoError(t, err) |
| 633 | |
| 634 | assert.Equal(t, destination1, destination2) |
| 635 | } |
| 636 | |
| 637 | // TestConcurrentPolicyCachingRaceCondition reproduces the "file exists" error |
| 638 | // that occurs when multiple workers simultaneously try to create symlinks from |
nothing calls this directly
no test coverage detected