Skip to content

Commit 2ab83fe

Browse files
authored
Merge pull request #71 from godaddy/v0.8.0
Upgrade to use asherah-cobhan v0.5.0
2 parents c840f36 + e02ed11 commit 2ab83fe

File tree

10 files changed

+164
-22
lines changed

10 files changed

+164
-22
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123

124124
services:
125125
mysql:
126-
image: mysql:5.7
126+
image: mysql:8.0
127127
env:
128128
MYSQL_DATABASE: ${{ env.MYSQL_DATABASE }}
129129
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_PASSWORD }}
@@ -145,18 +145,8 @@ jobs:
145145
run: |
146146
bundle exec rake download
147147
148-
- name: Initialize RDBMS metastore
149-
run: |
150-
mysql -h ${{ env.MYSQL_HOSTNAME }} -P${{ job.services.mysql.ports[3306] }} -u ${{ env.MYSQL_USERNAME }} -p${{ env.MYSQL_PASSWORD }} -e "CREATE TABLE ${{ env.MYSQL_DATABASE }}.encryption_key (
151-
id VARCHAR(255) NOT NULL,
152-
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
153-
key_record TEXT NOT NULL,
154-
PRIMARY KEY (id, created),
155-
INDEX (created)
156-
);"
157-
158148
- name: Set up Go
159-
uses: actions/setup-go@v6.2.0
149+
uses: actions/setup-go@v6.3.0
160150
with:
161151
go-version: 1.24
162152

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ Style/Documentation:
9595
Style/DocumentationMethod:
9696
Enabled: false # YARD comments are optional
9797

98+
Style/EmptyClassDefinition:
99+
Enabled: false
100+
98101
# Additional cops for code quality
99102
Lint/UnusedMethodArgument:
100103
Enabled: true

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## [Unreleased]
22

3+
## [0.8.0] - 2026-03-04
4+
5+
- Upgrade to use asherah-cobhan v0.5.0
6+
- Expose disable_zero_copy config option to disable zero-copy FFI input buffers
7+
38
## [0.7.0] - 2025-08-15
49

510
- Fix memory leak risks in buffer management

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
6969

7070
For tests requiring secrets (AWS KMS, database credentials), copy `.env.secrets.example` to `.env.secrets` and fill in the required values. The `.env.secrets` file is already in `.gitignore` to prevent accidental commits.
7171

72+
### Cross-Language Tests
73+
74+
Cross-language tests verify that data encrypted with the Go implementation can be decrypted with the Ruby implementation and vice versa.
75+
76+
**Prerequisites:**
77+
- MySQL running locally
78+
- Go 1.24+ installed
79+
80+
**Running the tests:**
81+
82+
```bash
83+
TEST_DB_PASSWORD=pass bin/cross-language-test.sh
84+
```
85+
86+
See `bin/cross-language-test.sh` for available environment variables and their defaults.
87+
7288
To install this gem onto your local machine, run `rake install`.
7389

7490
To release a new version, update the version number in `version.rb`, create and push a version tag:

bin/cross-language-test.sh

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,43 @@ ROOT_DIR=$(pwd)
66
ASHERAH_GO_DIR=$(pwd)/tmp/asherah
77
ASHERAH_GO_TEST_DIR=$(pwd)/tmp/asherah/tests/cross-language/go
88

9+
# Set database environment variables
10+
export TEST_DB_NAME=${TEST_DB_NAME:-testdb}
11+
export TEST_DB_USER=${TEST_DB_USER:-root}
12+
export TEST_DB_PASSWORD=${TEST_DB_PASSWORD:-}
13+
export TEST_DB_HOSTNAME=${TEST_DB_HOSTNAME:-localhost}
14+
export TEST_DB_PORT=${TEST_DB_PORT:-3306}
15+
16+
# Set Asherah environment variables
17+
export ASHERAH_SERVICE_NAME=${ASHERAH_SERVICE_NAME:-service}
18+
export ASHERAH_PRODUCT_NAME=${ASHERAH_PRODUCT_NAME:-product}
19+
export ASHERAH_KMS_MODE=${ASHERAH_KMS_MODE:-static}
20+
21+
# Initialize database and table
22+
echo "Initializing database..."
23+
MYSQL_CMD="mysql -h $TEST_DB_HOSTNAME -P$TEST_DB_PORT -u $TEST_DB_USER"
24+
if [ -n "$TEST_DB_PASSWORD" ]; then
25+
MYSQL_CMD="$MYSQL_CMD -p$TEST_DB_PASSWORD"
26+
fi
27+
28+
# Create database if it doesn't exist
29+
$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS $TEST_DB_NAME;" 2>/dev/null || {
30+
echo "Warning: Could not create database. It may already exist or you may not have permissions."
31+
}
32+
33+
# Create encryption_key table if it doesn't exist
34+
$MYSQL_CMD $TEST_DB_NAME <<'SQL' 2>/dev/null || echo "Warning: Could not create table. It may already exist or you may not have permissions."
35+
CREATE TABLE IF NOT EXISTS encryption_key (
36+
id VARCHAR(255) NOT NULL,
37+
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
38+
key_record TEXT NOT NULL,
39+
PRIMARY KEY (id, created),
40+
INDEX (created)
41+
);
42+
SQL
43+
44+
echo "Database initialization complete."
45+
946
# Clean tmp dir
1047
rm -rf $ASHERAH_GO_DIR
1148

@@ -19,11 +56,10 @@ cd $ASHERAH_GO_TEST_DIR
1956
go build ./...
2057
go mod edit -replace github.com/godaddy/asherah/go/appencryption=../../../go/appencryption
2158
go mod tidy
22-
go install github.com/cucumber/godog/cmd/godog@latest
2359

2460
# Encrypt with Go
2561
cd $ASHERAH_GO_TEST_DIR
26-
godog run "$ROOT_DIR/features/encrypt.feature"
62+
go run github.com/cucumber/godog/cmd/godog@latest run "$ROOT_DIR/features/encrypt.feature"
2763

2864
# Encrypt with Ruby
2965
cd $ROOT_DIR
@@ -35,4 +71,4 @@ bundle exec cucumber "$ROOT_DIR/features/decrypt.feature"
3571

3672
# Decrypt all with Go
3773
cd $ASHERAH_GO_TEST_DIR
38-
godog run "$ROOT_DIR/features/decrypt.feature"
74+
go run github.com/cucumber/godog/cmd/godog@latest run "$ROOT_DIR/features/decrypt.feature"

ext/asherah/checksums.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
version: v0.4.35
2-
libasherah-arm64.so: fad23a38e68e126374075adf197f0f431720aea9852deebe5f62d9240c935a66
3-
libasherah-x64.so: 8c52fc000df2c02fb2d1430afc3cd68e997f47f04b60d61481f8c4b201958ef8
4-
libasherah-arm64.dylib: 315bc41c85177a2b0c97f32e0af8e2694f393928678cbe648fdd8c16b8fe062a
5-
libasherah-x64.dylib: 848d3635713373e0482223087f454ff8464e36e7695e0ed19f830737288adaa9
1+
version: v0.5.0
2+
libasherah-arm64.so: 8271298c357808d7e6daa4ca81ded8f39c1947a55043abe3b32359e0f5840a6c
3+
libasherah-x64.so: 645c0da7d1330db511c6724f08154cfae3959610bd709d60eded1c1420d2fce8
4+
libasherah-arm64.dylib: 909097bf62207e6927a0184e41859ccf42a62afd711cdadf69b8c5672939468b
5+
libasherah-x64.dylib: e53ee66b7dd16ce587d5062e9eed8835f272653b6a91b4b5c5c1efd2ca97483e

features/support/env.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
DB_USER = ENV.fetch('TEST_DB_USER')
1111
DB_PASS = ENV.fetch('TEST_DB_PASSWORD')
1212
DB_PORT = ENV.fetch('TEST_DB_PORT')
13-
DB_HOST = 'localhost'
13+
DB_HOST = ENV.fetch('TEST_DB_HOSTNAME', 'localhost')
1414
CONNECTION_STRING = "#{DB_USER}:#{DB_PASS}@tcp(#{DB_HOST}:#{DB_PORT})/#{DB_NAME}?tls=skip-verify"
1515
TMP_DIR = '/tmp/'
1616
FILE_NAME = 'ruby_encrypted'

lib/asherah/config.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Asherah
2121
# @attr [Integer] expire_after, The amount of time in seconds a key is considered valid
2222
# @attr [Integer] check_interval, The amount of time in seconds before cached keys are considered stale
2323
# @attr [Boolean] enable_session_caching, Enable shared session caching
24+
# @attr [Boolean] disable_zero_copy, Disable zero-copy FFI input buffers to prevent use-after-free from caller runtime
2425
# @attr [Boolean] verbose, Enable verbose logging output
2526
class Config
2627
MAPPING = {
@@ -40,6 +41,7 @@ class Config
4041
session_cache_max_size: :SessionCacheMaxSize,
4142
session_cache_duration: :SessionCacheDuration,
4243
enable_session_caching: :EnableSessionCaching,
44+
disable_zero_copy: :DisableZeroCopy,
4345
expire_after: :ExpireAfter,
4446
check_interval: :CheckInterval,
4547
verbose: :Verbose

lib/asherah/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Asherah
4-
VERSION = '0.7.0'
4+
VERSION = '0.8.0'
55
end

spec/config_spec.rb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,94 @@
163163
end
164164
end
165165
end
166+
167+
describe '#disable_zero_copy' do
168+
it 'accepts disable_zero_copy as true' do
169+
expect {
170+
Asherah.configure do |config|
171+
base_config.call(config)
172+
config.disable_zero_copy = true
173+
end
174+
}.not_to raise_error
175+
Asherah.shutdown
176+
end
177+
178+
it 'accepts disable_zero_copy as false' do
179+
expect {
180+
Asherah.configure do |config|
181+
base_config.call(config)
182+
config.disable_zero_copy = false
183+
end
184+
}.not_to raise_error
185+
Asherah.shutdown
186+
end
187+
end
188+
189+
describe '#to_json' do
190+
it 'correctly maps all configuration options to Go JSON format' do
191+
config = Asherah::Config.new
192+
config.service_name = 'test-service'
193+
config.product_id = 'test-product'
194+
config.kms = 'aws'
195+
config.metastore = 'dynamodb'
196+
config.connection_string = 'mysql://localhost:3306/test'
197+
config.replica_read_consistency = 'eventual'
198+
config.sql_metastore_db_type = 'postgres'
199+
config.dynamo_db_endpoint = 'http://localhost:8000'
200+
config.dynamo_db_region = 'us-west-2'
201+
config.dynamo_db_table_name = 'test-table'
202+
config.enable_region_suffix = true
203+
config.region_map = { 'us-west-2' => 'arn' }
204+
config.preferred_region = 'us-west-2'
205+
config.session_cache_max_size = 500
206+
config.session_cache_duration = 3600
207+
config.enable_session_caching = true
208+
config.disable_zero_copy = true
209+
config.expire_after = 7200
210+
config.check_interval = 1800
211+
config.verbose = true
212+
213+
json_output = JSON.parse(config.to_json)
214+
215+
expect(json_output).to eq(
216+
'ServiceName' => 'test-service',
217+
'ProductID' => 'test-product',
218+
'KMS' => 'aws',
219+
'Metastore' => 'dynamodb',
220+
'ConnectionString' => 'mysql://localhost:3306/test',
221+
'ReplicaReadConsistency' => 'eventual',
222+
'SQLMetastoreDBType' => 'postgres',
223+
'DynamoDBEndpoint' => 'http://localhost:8000',
224+
'DynamoDBRegion' => 'us-west-2',
225+
'DynamoDBTableName' => 'test-table',
226+
'EnableRegionSuffix' => true,
227+
'RegionMap' => { 'us-west-2' => 'arn' },
228+
'PreferredRegion' => 'us-west-2',
229+
'SessionCacheMaxSize' => 500,
230+
'SessionCacheDuration' => 3600,
231+
'EnableSessionCaching' => true,
232+
'DisableZeroCopy' => true,
233+
'ExpireAfter' => 7200,
234+
'CheckInterval' => 1800,
235+
'Verbose' => true
236+
)
237+
end
238+
239+
it 'excludes nil values from JSON output' do
240+
config = Asherah::Config.new
241+
config.service_name = 'test-service'
242+
config.product_id = 'test-product'
243+
config.kms = 'test-debug-static'
244+
config.metastore = 'test-debug-memory'
245+
246+
json_output = JSON.parse(config.to_json)
247+
248+
expect(json_output).to eq(
249+
'ServiceName' => 'test-service',
250+
'ProductID' => 'test-product',
251+
'KMS' => 'test-debug-static',
252+
'Metastore' => 'test-debug-memory'
253+
)
254+
end
255+
end
166256
end

0 commit comments

Comments
 (0)