Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Maksym Trofimenko <[email protected]>
  • Loading branch information
Maksym Trofimenko committed Nov 19, 2023
1 parent a7078ca commit 0cfdf9e
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/controller/user/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package user

import (
"context"

"github.com/goharbor/harbor/src/common"
commonmodels "github.com/goharbor/harbor/src/common/models"
"github.com/goharbor/harbor/src/common/security"
Expand Down
15 changes: 15 additions & 0 deletions src/jobservice/job/impl/gdpr/audit_logs_data_masking.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package gdpr

import (
"fmt"

"github.com/goharbor/harbor/src/jobservice/job"
"github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/pkg/audit"
Expand Down
20 changes: 18 additions & 2 deletions src/jobservice/job/impl/gdpr/audit_logs_data_masking_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package gdpr

import (
"context"
"testing"

"github.com/stretchr/testify/assert"

"github.com/goharbor/harbor/src/jobservice/job"
mockjobservice "github.com/goharbor/harbor/src/testing/jobservice"
"github.com/goharbor/harbor/src/testing/pkg/audit"
"github.com/goharbor/harbor/src/testing/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
)

func TestAuditLogsCleanupJobShouldRetry(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions src/jobservice/job/known_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const (
ExecSweepVendorType = "EXECUTION_SWEEP"
// ScanAllVendorType: the name of the scan all job
ScanAllVendorType = "SCAN_ALL"
// AuditLogsGDPRCompliantVendorType : the name of the job which makes audit logs table GDPR-compliant
AuditLogsGDPRCompliantVendorType = "AUDIT_LOGS_GDPR_COMPLIANT"
// AuditLogsGDPRCompliantVendorType : the name of the job which makes audit logs table GDPR-compliant
AuditLogsGDPRCompliantVendorType = "AUDIT_LOGS_GDPR_COMPLIANT"
)

var (
Expand Down
17 changes: 9 additions & 8 deletions src/jobservice/runtime/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ package runtime
import (
"context"
"fmt"
"github.com/goharbor/harbor/src/jobservice/job/impl/gdpr"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"

"github.com/goharbor/harbor/src/jobservice/job/impl/gdpr"

"github.com/gomodule/redigo/redis"

"github.com/goharbor/harbor/src/jobservice/api"
Expand Down Expand Up @@ -328,13 +329,13 @@ func (bs *Bootstrap) loadAndRunRedisWorkerPool(
// In v2.2 we migrate the scheduled replication, garbage collection and scan all to
// the scheduler mechanism, the following three jobs are kept for the legacy jobs
// and they can be removed after several releases
"IMAGE_REPLICATE": (*legacy.ReplicationScheduler)(nil),
"IMAGE_GC": (*legacy.GarbageCollectionScheduler)(nil),
"IMAGE_SCAN_ALL": (*legacy.ScanAllScheduler)(nil),
job.SystemArtifactCleanupVendorType: (*systemartifact.Cleanup)(nil),
job.ExecSweepVendorType: (*task.SweepJob)(nil),
job.AuditLogsGDPRCompliantVendorType: (*gdpr.AuditLogsDataMasking)(nil),
}); err != nil {
"IMAGE_REPLICATE": (*legacy.ReplicationScheduler)(nil),
"IMAGE_GC": (*legacy.GarbageCollectionScheduler)(nil),
"IMAGE_SCAN_ALL": (*legacy.ScanAllScheduler)(nil),
job.SystemArtifactCleanupVendorType: (*systemartifact.Cleanup)(nil),
job.ExecSweepVendorType: (*task.SweepJob)(nil),
job.AuditLogsGDPRCompliantVendorType: (*gdpr.AuditLogsDataMasking)(nil),
}); err != nil {
// exit
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/audit/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Manager interface {
Delete(ctx context.Context, id int64) (err error)
// Purge delete the audit log with retention hours
Purge(ctx context.Context, retentionHour int, includeOperations []string, dryRun bool) (int64, error)
//UpdateUsername Replace all log records username with its hash
// UpdateUsername Replace all log records username with its hash
UpdateUsername(ctx context.Context, username string, replaceWith string) error
}

Expand Down
3 changes: 2 additions & 1 deletion src/testing/pkg/audit/dao/dao.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions src/testing/pkg/audit/manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/apitests/python/test_job_service_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setUp(self):
self.registry = Registry()
self.scan_all = ScanAll()
self.schedule = Schedule()
self.job_types = [ "GARBAGE_COLLECTION", "PURGE_AUDIT_LOG", "P2P_PREHEAT", "IMAGE_SCAN", "REPLICATION", "RETENTION", "SCAN_DATA_EXPORT", "SCHEDULER", "SLACK", "SYSTEM_ARTIFACT_CLEANUP", "WEBHOOK", "EXECUTION_SWEEP"]
self.job_types = [ "GARBAGE_COLLECTION", "PURGE_AUDIT_LOG", "P2P_PREHEAT", "IMAGE_SCAN", "REPLICATION", "RETENTION", "SCAN_DATA_EXPORT", "SCHEDULER", "SLACK", "SYSTEM_ARTIFACT_CLEANUP", "WEBHOOK", "EXECUTION_SWEEP", "AUDIT_LOGS_GDPR_COMPLIANT"]
self.cron_type = "Custom"
self.cron = "0 0 0 * * 0"

Expand Down

0 comments on commit 0cfdf9e

Please sign in to comment.