Skip to content

Commit

Permalink
dont show mac address outside hardware info
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Feb 23, 2024
1 parent 27ff09f commit 4dcf3c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 0 additions & 2 deletions app/views/v0/devices/_device.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ json.(
authorized = current_user && (current_user.is_admin? || (device.owner_id && current_user.id == device.owner_id))

if authorized
json.merge! mac_address: device.mac_address
json.merge! device_token: device.device_token
else
json.merge! mac_address: '[FILTERED]'
json.merge! device_token: '[FILTERED]'
end

Expand Down
18 changes: 9 additions & 9 deletions spec/requests/v0/devices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
expect(json.length).to eq(2)
# expect(json[0]['name']).to eq(first.name)
# expect(json[1]['name']).to eq(second.name)
expect(json[0].keys).to eq(%w(id uuid name description state postprocessing system_tags user_tags is_private notify_low_battery notify_stopped_publishing last_reading_at created_at updated_at mac_address device_token hardware owner data))
expect(json[0].keys).to eq(%w(id uuid name description state postprocessing system_tags user_tags is_private notify_low_battery notify_stopped_publishing last_reading_at created_at updated_at device_token hardware owner data))
end

describe "when not logged in" do
Expand Down Expand Up @@ -254,25 +254,25 @@

describe "mac_address" do

it "filters mac address from guests" do
it "filters hardware info from guests" do
j = api_get "devices/#{device.id}"
expect(j['mac_address']).to eq('[FILTERED]')
expect(j['hardware']['info']).to eq('[FILTERED]')
end

it "filters mac address from users" do
it "filters hardware info from users" do
j = api_get "devices/#{device.id}?access_token=#{token.token}"
expect(j['mac_address']).to eq('[FILTERED]')
expect(j['hardware']['info']).to eq('[FILTERED]')
end

it "exposes mac address to device owner" do
it "exposes hardware info to device owner" do
device = create(:device, owner: user)
j = api_get "devices/#{device.id}?access_token=#{token.token}"
expect(j['mac_address']).to eq(device.mac_address)
expect(j['hardware']['info']).to eq(device.hardware_info)
end

it "exposes mac address to admin" do
it "exposes hardware info address to admin" do
j = api_get "devices/#{device.id}?access_token=#{admin_token.token}"
expect(j['mac_address']).to eq(device.mac_address)
expect(j['hardware']['info']).to eq(device.hardware_info)
end

end
Expand Down

0 comments on commit 4dcf3c2

Please sign in to comment.