Skip to content

Commit bdcb9a3

Browse files
karesclaude
andcommitted
[compat] implement Store#add_path for certificate lookup
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 41521e8 commit bdcb9a3

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

src/main/java/org/jruby/ext/openssl/X509Store.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,26 @@ static RubyTime toTime(final ThreadContext context, final IRubyObject arg) {
166166

167167
@JRubyMethod
168168
public IRubyObject add_path(final ThreadContext context, final IRubyObject arg) {
169-
warn(context, "WARNING: unimplemented method called: OpenSSL::X509::Store#add_path");
170-
return context.nil;
169+
String path = arg.convertToString().toString();
170+
final Ruby runtime = context.runtime;
171+
try {
172+
if (store.loadLocations(runtime, null, path) != 1) {
173+
throw newStoreError(runtime, "X509_LOOKUP_add_dir");
174+
}
175+
}
176+
catch (RaiseException e) {
177+
throw e;
178+
}
179+
catch (Exception e) {
180+
debugStackTrace(runtime, e);
181+
throw newStoreError(runtime, "loading path failed: ", e);
182+
}
183+
return this;
171184
}
172185

173186
@JRubyMethod
174187
public IRubyObject add_file(final IRubyObject arg) {
175-
String file = arg.toString();
188+
String file = arg.convertToString().toString();
176189
final Ruby runtime = getRuntime();
177190
try {
178191
if (store.loadLocations(runtime, file, null) != 1) {

src/test/ruby/x509/test_x509store.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ def test_store_dup_clone_not_allowed
141141
assert_raise(NoMethodError) { store.clone }
142142
end
143143

144+
def test_add_path_returns_self
145+
store = OpenSSL::X509::Store.new
146+
assert_equal store, store.add_path("/etc/ssl/certs")
147+
end
148+
149+
def test_add_path_raises_with_empty_string
150+
store = OpenSSL::X509::Store.new
151+
assert_raise(OpenSSL::X509::StoreError) { store.add_path("") }
152+
end
153+
154+
def test_add_path_accepts_nonexistent_dir
155+
store = OpenSSL::X509::Store.new
156+
# CRuby accepts non-existent dirs (lazy lookup at verify time)
157+
assert_equal store, store.add_path("/nonexistent/path/to/certs")
158+
end
159+
144160
def test_use_non_existing_cert_file
145161
ENV['SSL_CERT_FILE'] = 'non-existing-file.crt'
146162
store = OpenSSL::X509::Store.new

0 commit comments

Comments
 (0)