Fix bug where "hostname" portion of author is missing or garbled

This commit is contained in:
Eric B. Budd 2022-12-20 22:13:32 -06:00 committed by Eric Budd
parent 2361933f81
commit d744eb023d
5 changed files with 77 additions and 13 deletions

View File

@ -1,5 +1,8 @@
# Changelog
## 1.1.2
* Fix bug where "hostname" portion of author is missing or garbled
## 1.1.1
* Make discarded message response more prominent
* Try nano if /usr/bin/vim is not set

View File

@ -596,7 +596,7 @@ Iris must:
* Deleted or edited messages should leave flags or placeholders for other users to know that other content was there before.
* The Iris client should expect that any message file could be missing, altered, or corrupted, and should handle those cases gracefully.
* Be portable
* All Iris files should be human-readable (and -editable, in a pinch)
* All Iris data files should be human-readable (and -editable, in a pinch)
* The use of the official Iris client should be optional for a user to manage his or her messages. A text editor should suffice.
* Other clients which follow the Iris file format should work seamlessly with the official Iris client.
* Be secure
@ -605,7 +605,7 @@ Iris must:
* Be a teacher
* Code should be clean, well-organized, and readable.
* Be limited in scope
* The source code should not exceed 1,000 LOC
* The source code should not exceed 1,000 SLOC
## Tests
@ -622,6 +622,20 @@ To run the tests:
ruby tests/iris_test.rb
```
```bash
Run options: --seed 11507
# Running:
.........................SSS.......SS.......S.....SSSSSSS....SSSSS
Finished in 0.107785s, 612.3294 runs/s, 677.2734 assertions/s.
66 runs, 73 assertions, 0 failures, 0 errors, 18 skips
You have skipped tests. Run with --verbose for details.
```
## Technical Bits
* [Dependencies](#dependencies)

View File

@ -10,6 +10,8 @@
* Flesh out technical sections
### Bugs
* Terrible slowdown when refreshing topics
* Performance is fine when no new topics show up
* Is `Time.now.utc.iso8601` working as expected?
* Fix bug when people are posting from different time zones
* Fix message ordering when editing/deleting multiple messages

23
iris.rb
View File

@ -27,13 +27,26 @@ class Config
HISTORY_FILE = "#{ENV['HOME']}/.iris.history"
IRIS_SCRIPT = __FILE__
USER = ENV['USER'] || ENV['LOGNAME'] || ENV['USERNAME']
HOSTNAME = `hostname -d`.chomp
AUTHOR = "#{USER}@#{HOSTNAME}"
ENV_EDITOR = ENV['EDITOR'].presence || `which nano`.chomp.presence
@@debug_mode = false
def self.hostname
return @hostname if @hostname
hostname = `hostname`.chomp
hostname = 'localhost' if hostname.empty?
return @hostname = hostname if hostname == 'localhost'
@hostname = hostname.split('.')[-2..-1].compact.join('.')
end
def self.author
user = ENV['USER'] || ENV['LOGNAME'] || ENV['USERNAME']
@author ||= "#{user}@#{self.hostname}"
end
def self.find_files
(`ls /home/**/.iris.messages`).split("\n")
end
@ -343,7 +356,7 @@ end
class Message
attr_reader :timestamp, :edit_hash, :author, :parent, :message, :errors, :is_deleted
def initialize(message, parent = nil, author = Config::AUTHOR, edit_hash = nil, timestamp = Time.now.utc.iso8601, is_deleted = nil)
def initialize(message, parent = nil, author = Config.author, edit_hash = nil, timestamp = Time.now.utc.iso8601, is_deleted = nil)
@message = message
@parent = parent
@author = author
@ -890,7 +903,7 @@ class Interface
end
def prompt
"#{Config::AUTHOR}~> "
"#{Config.author}~> "
end
def initialize(args)

View File

@ -24,16 +24,48 @@ describe Config do
_(Config::HISTORY_FILE).must_match /\/\.iris\.history$/
end
it 'has the username' do
_(Config::USER).must_equal 'jerryberry'
end
describe '.hostname' do
before do
Config.instance_variable_set(:@hostname, nil)
end
it 'has a hostname' do
_(Config::HOSTNAME).wont_be_nil
it 'has a hostname' do
_(Config.hostname).wont_be_nil
end
it 'correctly interprets an empty string' do
Config.expects(:`).with('hostname').returns('')
_(Config.hostname).must_equal 'localhost'
end
it 'correctly interprets localhost' do
Config.instance_variable_set(:@hostname, nil)
Config.expects(:`).with('hostname').returns('localhost')
_(Config.hostname).must_equal 'localhost'
end
it 'correctly interprets a subdomain' do
Config.instance_variable_set(:@hostname, nil)
Config.expects(:`).with('hostname').returns('example.com')
_(Config.hostname).must_equal 'example.com'
end
it 'correctly interprets a subsubdomain' do
Config.instance_variable_set(:@hostname, nil)
Config.expects(:`).with('hostname').returns('foo.example.com')
_(Config.hostname).must_equal 'example.com'
end
it 'correctly interprets an arbitrary number of subdomains' do
Config.instance_variable_set(:@hostname, nil)
Config.expects(:`).with('hostname').returns('foo.bar.baz.quux.example.com')
_(Config.hostname).must_equal 'example.com'
end
end
it 'has the author' do
_(Config::AUTHOR).must_equal "#{Config::USER}@#{Config::HOSTNAME}"
user = 'jerryberry'
_(Config.author).must_equal "#{user}@#{Config.hostname}"
end
it 'has the $EDITOR environment variable' do