Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions backend/plugins/bitbucket/api/connection_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,22 @@ func TestMergeFromRequest_HandlesUsesApiToken(t *testing.T) {
// After merge, UsesApiToken should be updated
// This is a structural test - actual merge logic is in the connection.go MergeFromRequest method
assert.True(t, connection.UsesApiToken, "Initial value should be true")

// If we were to apply the merge:
connection.UsesApiToken = newValues["usesApiToken"].(bool)
connection.Username = newValues["username"].(string)

assert.False(t, connection.UsesApiToken, "After merge, should be false")
assert.Equal(t, "new_username", connection.Username)
}

func TestConnectionStatusCodes(t *testing.T) {
// Test expected status code handling
tests := []struct {
name string
statusCode int
expectedError bool
errorType string
name string
statusCode int
expectedError bool
errorType string
}{
{
name: "Success - 200 OK",
Expand Down
34 changes: 17 additions & 17 deletions backend/plugins/gh-copilot/models/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ import "testing"
func TestGetTablesInfo(t *testing.T) {
tables := GetTablesInfo()
expected := map[string]bool{
(&GhCopilotConnection{}).TableName(): false,
(&GhCopilotScope{}).TableName(): false,
(&GhCopilotScopeConfig{}).TableName(): false,
(&GhCopilotOrgMetrics{}).TableName(): false,
(&GhCopilotLanguageMetrics{}).TableName(): false,
(&GhCopilotEnterpriseDailyMetrics{}).TableName(): false,
(&GhCopilotMetricsByIde{}).TableName(): false,
(&GhCopilotMetricsByFeature{}).TableName(): false,
(&GhCopilotMetricsByLanguageFeature{}).TableName(): false,
(&GhCopilotMetricsByLanguageModel{}).TableName(): false,
(&GhCopilotMetricsByModelFeature{}).TableName(): false,
(&GhCopilotUserDailyMetrics{}).TableName(): false,
(&GhCopilotUserMetricsByIde{}).TableName(): false,
(&GhCopilotUserMetricsByFeature{}).TableName(): false,
(&GhCopilotConnection{}).TableName(): false,
(&GhCopilotScope{}).TableName(): false,
(&GhCopilotScopeConfig{}).TableName(): false,
(&GhCopilotOrgMetrics{}).TableName(): false,
(&GhCopilotLanguageMetrics{}).TableName(): false,
(&GhCopilotEnterpriseDailyMetrics{}).TableName(): false,
(&GhCopilotMetricsByIde{}).TableName(): false,
(&GhCopilotMetricsByFeature{}).TableName(): false,
(&GhCopilotMetricsByLanguageFeature{}).TableName(): false,
(&GhCopilotMetricsByLanguageModel{}).TableName(): false,
(&GhCopilotMetricsByModelFeature{}).TableName(): false,
(&GhCopilotUserDailyMetrics{}).TableName(): false,
(&GhCopilotUserMetricsByIde{}).TableName(): false,
(&GhCopilotUserMetricsByFeature{}).TableName(): false,
(&GhCopilotUserMetricsByLanguageFeature{}).TableName(): false,
(&GhCopilotUserMetricsByLanguageModel{}).TableName(): false,
(&GhCopilotUserMetricsByModelFeature{}).TableName(): false,
(&GhCopilotSeat{}).TableName(): false,
(&GhCopilotUserMetricsByLanguageModel{}).TableName(): false,
(&GhCopilotUserMetricsByModelFeature{}).TableName(): false,
(&GhCopilotSeat{}).TableName(): false,
}

if len(tables) != len(expected) {
Expand Down
2 changes: 1 addition & 1 deletion backend/plugins/gh-copilot/models/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestGhCopilotScope_BeforeSave_BaselinePeriodDays(t *testing.T) {
Id: "test-org",
BaselinePeriodDays: tt.input,
}
err := s.BeforeSave(nil)
err := s.BeforeSave(nil)
if err != nil {
t.Errorf("BeforeSave() error = %v, want nil", err)
}
Expand Down
112 changes: 56 additions & 56 deletions backend/plugins/github/tasks/cicd_job_convertor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,63 +68,63 @@ func BenchmarkGenJobID(b *testing.B) {
}

func TestConvertJobs_SkipNoStartedAt(t *testing.T) {
job := &models.GithubJob{
ID: 123,
RunID: 456,
Name: "test-job",
StartedAt: nil,
}

convert := func(inputRow interface{}) ([]interface{}, error) {
line := inputRow.(*models.GithubJob)
if line.StartedAt == nil {
return nil, nil
}
createdAt := *line.StartedAt
domainJob := &devops.CICDTask{
Name: line.Name,
TaskDatesInfo: devops.TaskDatesInfo{
CreatedDate: createdAt,
StartedDate: line.StartedAt,
FinishedDate: line.CompletedAt,
},
}
return []interface{}{domainJob}, nil
}

result, err := convert(job)
assert.Nil(t, err)
assert.Nil(t, result)
job := &models.GithubJob{
ID: 123,
RunID: 456,
Name: "test-job",
StartedAt: nil,
}

convert := func(inputRow interface{}) ([]interface{}, error) {
line := inputRow.(*models.GithubJob)
if line.StartedAt == nil {
return nil, nil
}
createdAt := *line.StartedAt
domainJob := &devops.CICDTask{
Name: line.Name,
TaskDatesInfo: devops.TaskDatesInfo{
CreatedDate: createdAt,
StartedDate: line.StartedAt,
FinishedDate: line.CompletedAt,
},
}
return []interface{}{domainJob}, nil
}

result, err := convert(job)
assert.Nil(t, err)
assert.Nil(t, result)
}

func TestConvertJobs_WithStartedAt(t *testing.T) {
now := time.Now()
job := &models.GithubJob{
ID: 123,
RunID: 456,
Name: "test-job",
StartedAt: &now,
}

convert := func(inputRow interface{}) ([]interface{}, error) {
line := inputRow.(*models.GithubJob)
if line.StartedAt == nil {
return nil, nil
}
createdAt := *line.StartedAt
domainJob := &devops.CICDTask{
Name: line.Name,
TaskDatesInfo: devops.TaskDatesInfo{
CreatedDate: createdAt,
StartedDate: line.StartedAt,
FinishedDate: line.CompletedAt,
},
}
return []interface{}{domainJob}, nil
}

result, err := convert(job)
assert.Nil(t, err)
assert.NotNil(t, result)
assert.Equal(t, "test-job", result[0].(*devops.CICDTask).Name)
now := time.Now()
job := &models.GithubJob{
ID: 123,
RunID: 456,
Name: "test-job",
StartedAt: &now,
}

convert := func(inputRow interface{}) ([]interface{}, error) {
line := inputRow.(*models.GithubJob)
if line.StartedAt == nil {
return nil, nil
}
createdAt := *line.StartedAt
domainJob := &devops.CICDTask{
Name: line.Name,
TaskDatesInfo: devops.TaskDatesInfo{
CreatedDate: createdAt,
StartedDate: line.StartedAt,
FinishedDate: line.CompletedAt,
},
}
return []interface{}{domainJob}, nil
}

result, err := convert(job)
assert.Nil(t, err)
assert.NotNil(t, result)
assert.Equal(t, "test-job", result[0].(*devops.CICDTask).Name)
}
18 changes: 9 additions & 9 deletions backend/plugins/jira/tasks/epic_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ func TestEpicCollectorBatchSizeLogic(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
// Test the batch size logic from CollectEpics function
batchSize := 100

// Replicate the exact logic from CollectEpics
if strings.EqualFold(string(tt.deploymentType), string(models.DeploymentServer)) &&
len(tt.versionNumbers) == 3 &&
tt.versionNumbers[0] <= 8 {
if strings.EqualFold(string(tt.deploymentType), string(models.DeploymentServer)) &&
len(tt.versionNumbers) == 3 &&
tt.versionNumbers[0] <= 8 {
batchSize = 1
}

if batchSize != tt.expectedBatch {
t.Errorf("Batch size for %s with version %v: got %d, want %d",
t.Errorf("Batch size for %s with version %v: got %d, want %d",
tt.deploymentType, tt.versionNumbers, batchSize, tt.expectedBatch)
}
})
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestEpicCollectorDeploymentTypeLogic(t *testing.T) {
isServer := strings.EqualFold(string(tt.deploymentType), string(models.DeploymentServer))

if isServer != tt.expectServer {
t.Errorf("Deployment type detection for %s: got isServer=%v, want %v",
t.Errorf("Deployment type detection for %s: got isServer=%v, want %v",
tt.deploymentType, isServer, tt.expectServer)
}
})
Expand Down Expand Up @@ -201,17 +201,17 @@ func TestEpicCollectorApiEndpointSelection(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
// Test the API endpoint selection logic from CollectEpics function
var selectedEndpoint string

if strings.EqualFold(string(tt.deploymentType), string(models.DeploymentServer)) {
selectedEndpoint = "api/2/search"
} else {
selectedEndpoint = "api/3/search/jql"
}

if selectedEndpoint != tt.expectedEndpoint {
t.Errorf("API endpoint selection for %s: got %s, want %s",
t.Errorf("API endpoint selection for %s: got %s, want %s",
tt.deploymentType, selectedEndpoint, tt.expectedEndpoint)
}
})
}
}
}
2 changes: 1 addition & 1 deletion backend/plugins/table_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import (
bitbucket "github.com/apache/incubator-devlake/plugins/bitbucket/impl"
bitbucket_server "github.com/apache/incubator-devlake/plugins/bitbucket_server/impl"
circleci "github.com/apache/incubator-devlake/plugins/circleci/impl"
copilot "github.com/apache/incubator-devlake/plugins/gh-copilot/impl"
customize "github.com/apache/incubator-devlake/plugins/customize/impl"
dbt "github.com/apache/incubator-devlake/plugins/dbt/impl"
dora "github.com/apache/incubator-devlake/plugins/dora/impl"
feishu "github.com/apache/incubator-devlake/plugins/feishu/impl"
copilot "github.com/apache/incubator-devlake/plugins/gh-copilot/impl"
gitee "github.com/apache/incubator-devlake/plugins/gitee/impl"
gitextractor "github.com/apache/incubator-devlake/plugins/gitextractor/impl"
github "github.com/apache/incubator-devlake/plugins/github/impl"
Expand Down
4 changes: 2 additions & 2 deletions backend/server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func SetupApiServer(router *gin.Engine) {
router.UseRawPath = true
// router.UnescapePathValues = false

// Endpoint to proceed database migration
router.GET("/proceed-db-migration", func(ctx *gin.Context) {
// Endpoint to proceed database migration (now requires authentication)
router.GET("/proceed-db-migration", auth.RequireAuth(), func(ctx *gin.Context) {
// Execute database migration
errors.Must(services.ExecuteMigration())
// Return success response
Expand Down
19 changes: 9 additions & 10 deletions backend/server/api/auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ import (
// and clear its session even when the cookie has lapsed; both handlers
// short-circuit gracefully when no user is set.
var publicPaths = map[string]struct{}{
"/ping": {},
"/ready": {},
"/health": {},
"/version": {},
"/proceed-db-migration": {},
PathMethods: {},
PathLogin: {},
PathCallback: {},
PathLogout: {},
PathUserInfo: {},
"/ping": {},
"/ready": {},
"/health": {},
"/version": {},
PathMethods: {},
PathLogin: {},
PathCallback: {},
PathLogout: {},
PathUserInfo: {},
}

func OIDCAuthentication() gin.HandlerFunc { return defaultService.OIDCAuthentication() }
Expand Down
1 change: 1 addition & 0 deletions backend/test/helper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func ConnectLocalServer(t *testing.T, clientConfig *LocalClientConfig) *DevlakeC
api.CreateAndRunApiServer()
})
}()
// NOTE: /proceed-db-migration now requires authentication. If AUTH_ENABLED=true, this test must provide credentials.
req, err2 := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/proceed-db-migration", addr), nil)
require.NoError(t, err2)
d.forceSendHttpRequest(100, req, func(err errors.Error) bool {
Expand Down
Loading