Fixes #14758
First two commits are tidy-ups which I feel are worthwhile as they are very straightforward, cut down the file by 50%, and made the final diff more minimal. Happy to squash after review.
178 | 179 | - #Wrong password for randomly generated user 180 | - self.log.info('Wrong...') 181 | - authpairnew = self.user+":"+self.password+"Wrong" 182 | - headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)} 183 | + password = "cA773lm788buwYe4g4WT+05pKyNruVKjQ25x3n0DQcM="
Minor: maybe rename this rtpassword or something similar to avoid confusion with self.password?
Fixed.
233 | - conn.request('POST', '/', '{"method": "getbestblockhash"}', headers) 234 | - resp = conn.getresponse() 235 | - assert_equal(resp.status, 401) 236 | - conn.close() 237 | - 238 | + self.test_auth(self.nodes[1], "rpcuser💻", "rpcpassword🔑")
Why do we have emojis in the code?
it's arbitrary, but the thinking is: if it can handle emoji, it can handle any UTF symbol
Just because it can handle emojis doesn't mean it's a good idea to use. Can we remove them?
We are already using emojis elsewhere in the functional test suite.
Emojis are UTF symbols. It is good to test that we are able to handle UTF symbols, especially in places that people may have entered them such as the configuration files where there may be UTF symbols in passwords or file paths. As such, it would be detrimental to remove them as otherwise we are losing the tests for these.
You don't clarify why it is not a good idea, so I am not sure what you are getting at. But in general, I would add that it would be better to have an explicit test for the usage of UTF symbols and not an implicit test within another test.
While I agree that separating tests for "if rpcuser/rpcpassword works at all" from "if rpcuser/rpcpassword works with UTF-8" is worthwhile, it is beyond the scope of this PR.
However, this separation looks like an easy enough change, and perhaps if @fjahr or @fqlx feel strongly about this they can take this up in a separate PR.
UTF handling is not optional in this day and age. I think we should keep this as-is.
58 | + p = subprocess.Popen([sys.executable, gen_rpcauth, 'rt2', self.rt2password], stdout=subprocess.PIPE, universal_newlines=True) 59 | + lines = p.stdout.read().splitlines() 60 | + rpcauth2 = lines[1] 61 | + 62 | + # Generate RPCAUTH without specifying password 63 | + self.user = ''.join(SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(10))
Nit: Why do you generate a random username here instead of just hardcoding one?
Cuz it was originally done this way. Not really within scope but good catch!
183 | - #Wrong password for randomly generated user 184 | - self.log.info('Wrong...') 185 | - authpairnew = self.user+":"+self.password+"Wrong" 186 | - headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)} 187 | + self.log.info('Correct...') 188 | + assert_equal(200, call_with_auth(self.nodes[0], url.username, url.password).status)
Nit: Could this not also use the test_auth function?
Done!
ACK 1d5312a Good refactoring! Ran test locally, checked that they could fail, reviewed code.
Looks like the "tidy up run_test" commit was duplicated!
Good refactoring! Ran test locally, checked that they could fail, reviewed code.
Thanks for reviewing/testing.
Looks like the "tidy up run_test" commit was duplicated!
Good refactoring! Ran test locally, checked that they could fail, reviewed code.
Thanks for reviewing/testing.
Oh they're not duplicates, both tidy-ups but easier to review when separate. :-) I'm gunna squash everything together after review.
I think they should be kept separate commits, to make review after merge easier and preserve history for future reference.
Since we're not squashing, I reworded the commit messages to be more descriptive and rebased.
ACK e263a343d4b6a2622df6bb734cd9d51a0d20a663