Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Samr::UserProperties #285

Merged
merged 1 commit into from
Mar 14, 2025
Merged
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
76 changes: 76 additions & 0 deletions spec/lib/ruby_smb/dcerpc/samr/user_properties_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
RSpec.describe RubySMB::Dcerpc::Samr::UserProperties do
describe '#read' do
context 'when reading a structure with no user properties' do
let(:binary) { [ 0, 0x63, 0, 0, 0x50, 0].pack('L<L<S<S<x96<SC') }
let(:subject) { described_class.read(binary) }

it 'does not include the property_count' do
expect(subject.property_count?).to be_falsey
expect(subject.snapshot).to_not include(:property_count)
end

it 'does not include the user_properties' do
expect(subject.user_properties?).to be_falsey
expect(subject.snapshot).to_not include(:user_properties)
end

it 'serializes to the value that was read' do
expect(subject.to_binary_s).to eq(binary)
end
end

context 'when reading a structure with two user properties' do
let(:user_property1) { RubySMB::Dcerpc::Samr::UserProperty.new(property_name: 'key1', property_value: 'value1') }
let(:user_property2) { RubySMB::Dcerpc::Samr::UserProperty.new(property_name: 'key2', property_value: 'value2') }
let(:user_properties) { user_property1.to_binary_s + user_property2.to_binary_s }
let(:binary) { [ 0, 0x63 + 2 + user_properties.length, 0, 0, 0x50, 2].pack('L<L<S<S<x96<S<S') + user_properties + "\x00".b }
let(:subject) { described_class.read(binary) }

it 'includes the property_count' do
expect(subject.property_count?).to be_truthy
expect(subject.property_count).to eq(2)
expect(subject.snapshot).to include(:property_count)
end

it 'includes the user_properties' do
expect(subject.user_properties?).to be_truthy
expect(subject.user_properties).to eq([user_property1, user_property2])
expect(subject.snapshot).to include(:user_properties)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here?

Suggested change
expect(subject.snapshot).to include(:user_properties)
expect(subject.snapshot).to include(:user_properties)
expect(subject.user_properties).to eq([user_property1, user_property2])

end

it 'serializes to the value that was read' do
expect(subject.to_binary_s).to eq(binary)
end

context 'when #user_properties is cleared' do
before(:each) { subject.user_properties.clear }

it 'does not include the property_count' do
expect(subject.property_count?).to be_falsey
expect(subject.snapshot).to_not include(:property_count)
end

it 'does not include the user_properties' do
expect(subject.user_properties?).to be_falsey
expect(subject.snapshot).to_not include(:user_properties)
end
end
Comment on lines +45 to +57
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one here highlights the behavior that has been a problem in the past where the state of user_properties needs to be synced properly.

end
end

describe '#initialize' do
let(:subject) { described_class.new }

it 'initializes #struct_length to 0x63' do
expect(subject.struct_length).to eq(0x63)
end

it 'initializes #property_signature to 0x50' do
expect(subject.property_signature).to eq(0x50)
end

it 'does not include user_properties' do
expect(subject.user_properties).to be_empty
end
end
end
Loading