File tree 2 files changed +19
-1
lines changed 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
60
60
end
61
61
62
62
def token
63
- return @token if @token
63
+ return @token if @token_computed
64
64
# Allow nil in config to skip loading a token
65
65
if @settings . include? ( 'token' )
66
66
if @settings [ 'token' ]
@@ -69,6 +69,12 @@ def token
69
69
elsif File . exist? ( DEFAULT_TOKEN )
70
70
@token = File . read ( DEFAULT_TOKEN )
71
71
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
72
78
@token = @token . strip if @token
73
79
end
74
80
Original file line number Diff line number Diff line change 72
72
context "token" do
73
73
context "token is valid" do
74
74
before :each do
75
+ options . delete ( 'cert' )
76
+ options . delete ( 'key' )
75
77
allow ( File ) . to receive ( :read ) . with ( token ) . and_return 'footoken'
76
78
allow ( File ) . to receive ( :read ) . with ( Bolt ::PuppetDB ::Config ::DEFAULT_TOKEN ) . and_return 'bartoken'
77
79
end
97
99
98
100
context "token is invalid" do
99
101
before :each do
102
+ options . delete ( 'cert' )
103
+ options . delete ( 'key' )
100
104
allow ( File ) . to receive ( :read ) . with ( token ) . and_return "footoken\n "
101
105
allow ( File ) . to receive ( :read ) . with ( Bolt ::PuppetDB ::Config ::DEFAULT_TOKEN ) . and_return "bartoken\n "
102
106
end
112
116
expect ( config . token ) . to eq ( 'bartoken' )
113
117
end
114
118
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
115
127
end
116
128
117
129
context "cacert" do
You can’t perform that action at this time.
0 commit comments