nexpose-client icon indicating copy to clipboard operation
nexpose-client copied to clipboard

user.save(connection) causes a Null Pointer Exception

Open jameswhite opened this issue 7 years ago • 1 comments

Expected Behavior

When creating a user and setting the authsrcid to one that exists on another user, I'd expect it to create a user, tell me why it didn't create. I would not expect a Null pointer exception to be thrown.

Current Behavior

Possible Solution

Steps to Reproduce (for bugs)

Run the code below

Ruby code that reproduces the issue:

#!/usr/bin/env ruby
require 'pp'
require 'nexpose'
include Nexpose

nsc = Connection.new(ENV['NEXPOSE_HOST'],ENV['NEXPOSE_USER'],ENV['NEXPOSE_PASS'],ENV['NEXPOSE_PORT'])
nsc.login
at_exit { nsc.logout }
roles = [ 'global-admin', 'security-manager', 'site-admin', 'system-admin', 'user', 'custom', 'controls-insight-only' ]

id = nil;
nsc.users.each { |user| id = user.id if user.name == "jameswhite" }
user = Nexpose::User.load(nsc,id)
pp user

puts

user = Nexpose::User.new("jayswan","Jay Swan", nil, roles[4], id=-1, 1, "[email protected]", all_sites = true, all_groups = true)
user.authsrcid = "1"
PP.pp user

result = user.save(nsc)
PP.pp result

exit

Output

#<Nexpose::User:0x007feeaa2687c0
 @all_groups=true,
 @all_sites=true,
 @authsrcid="1",
 @email="[email protected]",
 @enabled=1,
 @full_name="James White",
 @groups=[],
 @id="12",
 @name="jameswhite",
 @password=nil,
 @role_name="global-admin",
 @sites=[],
 @token=nil>

#<Nexpose::User:0x007feeaa243cb8
 @all_groups=true,
 @all_sites=true,
 @authsrcid="1",
 @email="[email protected]",
 @enabled=1,
 @full_name="Jay Swan",
 @groups=[],
 @id=-1,
 @name="jayswan",
 @password=nil,
 @role_name="user",
 @sites=[],
 @token=nil>
bundler: failed to load command: examples/nexpose_users.rb (examples/nexpose_users.rb)
Nexpose::APIError: NexposeAPI: Action failed: java.lang.NullPointerException
  /Users/jameswhite/dev/jameswhite/nexpose-client/lib/nexpose/api_request.rb:148:in `execute'
  /Users/jameswhite/dev/jameswhite/nexpose-client/lib/nexpose/connection.rb:124:in `execute'
  /Users/jameswhite/dev/jameswhite/nexpose-client/lib/nexpose/user.rb:144:in `save'
  examples/nexpose_users.rb:22:in `<top (required)>'

Context

Just trying to provision users that are backed by an OpenLDAP Authentication source.

Your Environment

ruby: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
nexpose-client: https://github.com/rapid7/nexpose-client/commit/24c17867b444fbd240f6b1f8d722d4aed5ad9d77
operating system: macOS High Sierra 10.13.3 (17D47)
Nexpose product version: 6.5.5

jameswhite avatar Feb 13 '18 23:02 jameswhite

Does your nsc.log from Nexpose show a stack trace for this? If so can you paste it here?

gschneider-r7 avatar Feb 20 '18 22:02 gschneider-r7