Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
574ccef
🐛 fix(deps): resolve licenses for local path ruby dependencies
pboling Dec 19, 2025
7458fe9
🐛 fix(deps): recursive resolution for gemspecs
pboling Dec 19, 2025
8798520
Comment alignment
pboling Dec 19, 2025
3c3b463
🐛 fix(deps): Reset currentRemotePath to empty string when entering a …
pboling Dec 19, 2025
acd7506
🐛 fix(ruby): improve dependency resolution and license detection
pboling Dec 19, 2025
2450f0f
📝 docs(ruby): Fix comment
pboling Dec 19, 2025
7f71c92
🚨 lint(ruby): Fix lint issues
pboling Dec 19, 2025
2641522
🚨 docs(ruby): Improve comments
pboling Dec 19, 2025
3bda4e6
🐛 fix(deps): verify gemspec name matches requested dependency
pboling Dec 19, 2025
18ecc33
🐛 fix: use regex to validate ruby gem versions
pboling Dec 19, 2025
4e3c76e
♻️ refactor: remove unused parseGemspecLicense function
pboling Dec 19, 2025
d9d4687
🐛 fix: support multiple licenses in gemspec
pboling Dec 19, 2025
5babc6d
📝 docs: add documentation for GemspecResolver
pboling Dec 19, 2025
614c6fa
Reduce duplication
pboling Dec 19, 2025
490aede
📄 docs: Add license headers
pboling Dec 19, 2025
73cd108
🚨 lint: Linting fixes
pboling Dec 19, 2025
b9da96a
Improve regex
pboling Dec 19, 2025
8971e77
Lint fix
pboling Dec 19, 2025
7151456
Documentation
pboling Dec 19, 2025
19d3e9d
Stricter matching.
pboling Dec 19, 2025
cc79268
Stricter matching
pboling Dec 19, 2025
86c60e6
🚨 lint: Linting fixes
pboling Dec 19, 2025
ef710c1
🐛 fix: ignored scanner error in parseGemspecInfo
pboling Dec 19, 2025
aabc7f7
🐛 feat: log warning when multiple licenses are found in gemspec
pboling Dec 19, 2025
49f287d
🐛 fix: reset currentRemotePath when entering PATH block
pboling Dec 19, 2025
f16ba0a
🔒️ Prevent unsafe path traversal
pboling Dec 19, 2025
8312c6e
🐛 fix: add depth limit to gemspec dependency resolution
pboling Dec 19, 2025
f1784e8
♻️ Refactor: Rename currentRemotePath to currentLocalPath in Gemfile.…
pboling Dec 19, 2025
c84b648
✅ test: strengthen citrus local dependency test
pboling Dec 19, 2025
31dbcf9
📝 docs: document limitation of ignoring version constraints in gemspecs
pboling Dec 19, 2025
0fb3ded
📝 docs: clarify comment on gem license resolution order
pboling Dec 19, 2025
9f8ce0a
🐛 fix: refine gemspec license regex to avoid capturing invalid content
pboling Dec 19, 2025
9733254
♻️ Refactor: Move internal logger to pkg/logger and update references
pboling Dec 19, 2025
ce8ff84
🔥 refactor: remove unreachable code in ruby dependency resolution
pboling Dec 19, 2025
89b4db5
feat: improve ruby dependency graph resolution
pboling Dec 20, 2025
98631c0
♻️ Refactor: Optimize Ruby gem lookup with caching
pboling Dec 20, 2025
3625d88
✅ test: add coverage for Ruby license fetching and path traversal
pboling Dec 20, 2025
a642a6c
♻️ feat: treat multiple gemspec licenses as 'AND' relationship
pboling Dec 20, 2025
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
153 changes: 153 additions & 0 deletions pkg/deps/gemspec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 deps

import (
"os"
"path/filepath"
"testing"
)

const (
tomlRb = "toml-rb"
citrus = "citrus"
mit = "MIT"
)

func TestRubyGemspecResolver(t *testing.T) {
resolver := new(GemspecResolver)

// toml-merge case: parse gemspec, detect license and dependencies
{
tmp := t.TempDir()
if err := copyRuby("testdata/ruby/toml-merge", tmp); err != nil {
t.Fatal(err)
}
gemspec := filepath.Join(tmp, "toml-merge.gemspec")
if !resolver.CanResolve(gemspec) {
t.Fatalf("GemspecResolver cannot resolve %s", gemspec)
}
cfg := &ConfigDeps{Files: []string{gemspec}}
report := Report{}
if err := resolver.Resolve(gemspec, cfg, &report); err != nil {
t.Fatal(err)
}

// Expect toml-rb dependency.
found := false
for _, r := range report.Resolved {
if r.Dependency == tomlRb {
found = true
break
}
}
for _, r := range report.Skipped {
if r.Dependency == tomlRb {
found = true
break
}
}
if !found {
t.Errorf("expected toml-rb dependency, got %v", report.Resolved)
}
}

// citrus case: transitive dependency resolution via installed gems
{
tmp := t.TempDir()
gemHome := filepath.Join(tmp, "gemhome")
specsDir := filepath.Join(gemHome, "specifications")
if err := os.MkdirAll(specsDir, 0o755); err != nil {
t.Fatal(err)
}
t.Setenv("GEM_HOME", gemHome)

// Create toml-rb gemspec (dependency of toml-merge)
tomlRbContent := `
Gem::Specification.new do |s|
s.name = 'toml-rb'
s.version = '1.0.0'
s.add_dependency 'citrus', '~> 3.0'
end
`
if err := writeFileRuby(filepath.Join(specsDir, "toml-rb-1.0.0.gemspec"), tomlRbContent); err != nil {
t.Fatal(err)
}

// Create citrus gemspec (dependency of toml-rb)
citrusContent := `
Gem::Specification.new do |s|
s.name = 'citrus'
s.version = '3.0.2'
s.licenses = ['MIT']
end
`
if err := writeFileRuby(filepath.Join(specsDir, "citrus-3.0.2.gemspec"), citrusContent); err != nil {
t.Fatal(err)
}

// Create toml-merge gemspec (the project file)
tomlMergeContent := `
Gem::Specification.new do |s|
s.name = 'toml-merge'
s.version = '0.0.1'
s.add_dependency 'toml-rb', '~> 1.0'
end
`
gemspec := filepath.Join(tmp, "toml-merge.gemspec")
if err := writeFileRuby(gemspec, tomlMergeContent); err != nil {
t.Fatal(err)
}

cfg := &ConfigDeps{Files: []string{gemspec}}
report := Report{}
if err := resolver.Resolve(gemspec, cfg, &report); err != nil {
t.Fatal(err)
}

// Check for citrus
found := false
var license string
for _, r := range report.Resolved {
if r.Dependency == citrus {
found = true
license = r.LicenseSpdxID
break
}
}
if !found {
// Check skipped
for _, r := range report.Skipped {
if r.Dependency == citrus {
found = true
license = r.LicenseSpdxID
break
}
}
}

if !found {
t.Error("expected citrus dependency (transitive)")
} else {
t.Logf("citrus license: %s", license)
if license != mit {
t.Errorf("expected citrus license MIT, got %s", license)
}
}
}
}
1 change: 1 addition & 0 deletions pkg/deps/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var Resolvers = []Resolver{
new(JarResolver),
new(CargoTomlResolver),
new(GemfileLockResolver),
new(GemspecResolver),
}

func Resolve(config *ConfigDeps, report *Report) error {
Expand Down
Loading