File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ def self.default_config
6060 end
6161
6262 def token
63- return @token if @token
63+ return @token if @token_computed
6464 # Allow nil in config to skip loading a token
6565 if @settings . include? ( 'token' )
6666 if @settings [ 'token' ]
@@ -69,6 +69,12 @@ def token
6969 elsif File . exist? ( DEFAULT_TOKEN )
7070 @token = File . read ( DEFAULT_TOKEN )
7171 end
72+ # Only use cert based auth in the case token and cert are both configured
73+ if @token && cert
74+ Bolt ::Logger . logger ( self ) . debug ( "Both cert and token based auth configured, using cert only" )
75+ @token = nil
76+ end
77+ @token_computed = true
7278 @token = @token . strip if @token
7379 end
7480
Original file line number Diff line number Diff line change 7272 context "token" do
7373 context "token is valid" do
7474 before :each do
75+ options . delete ( 'cert' )
76+ options . delete ( 'key' )
7577 allow ( File ) . to receive ( :read ) . with ( token ) . and_return 'footoken'
7678 allow ( File ) . to receive ( :read ) . with ( Bolt ::PuppetDB ::Config ::DEFAULT_TOKEN ) . and_return 'bartoken'
7779 end
9799
98100 context "token is invalid" do
99101 before :each do
102+ options . delete ( 'cert' )
103+ options . delete ( 'key' )
100104 allow ( File ) . to receive ( :read ) . with ( token ) . and_return "footoken\n "
101105 allow ( File ) . to receive ( :read ) . with ( Bolt ::PuppetDB ::Config ::DEFAULT_TOKEN ) . and_return "bartoken\n "
102106 end
112116 expect ( config . token ) . to eq ( 'bartoken' )
113117 end
114118 end
119+
120+ context "both token and cert" do
121+ it "returns nil for token when cert is configured" do
122+ allow ( config ) . to receive ( :validate_file_exists ) . with ( 'cert' ) . and_return true
123+ allow ( File ) . to receive ( :read ) . with ( token ) . and_return 'footoken'
124+ expect ( config . token ) . to be_nil
125+ end
126+ end
115127 end
116128
117129 context "cacert" do
You can’t perform that action at this time.
0 commit comments