Issue 14: Wildcard hosts#19
Conversation
* Add test for prefixed and trailing wildcard, and ensure both cases are handled correctly. * Accidentally covered a few uncovered lines in `lexer.go` with the new tests.
* Added logic to handle MACs, Ciphers and Forwards. * Added tests for the mentioned additions. * Currently we are **only** appending to the fields of the basic host config. That means that it gets its own values *and* those of the wildcard host.
…d host handling in `Includes` I thought about the best way to do it, and came up with the decision to **not** duplicate code. This required the breakdown of the `parse` function, and the creation of a function that would handle **ONLY** the extraction of host data. Without default values and such. It has a boolean parameter to return either only the virtual or actual hosts.
|
So, the last commit does a big change in my opinion, and I will try to explain my train of thoughts. At the beginning I was using two variables to save Virtual and Actual hosts in the
So using option 3, I separated a large chunk of the code in a new function. Tests pass, coverage did not drop and the virtual hosts seem to be working correctly now. Of course I understand this might not be so easy to review but I'm willing to assist any way I can. |
Issue: #14
Currently this PR is marked as draft, because I'd love to clear out the
TODOat the bottom and probably address requests from reviews if there are such.Still I've tested this locally and at the moment it suits my (rather basic) needs well.
Here is a quick outline of the made changes:
Changes
Portvalue is read from config or if we are using the hardcoded one.sshConfigsarray, we cycle through it and in case thePortis0(the default one) we set it to22.wildcardHostsvariable. Where we were adding the host to the config, now we do additional check to see if it is an actual host or a wildcard one. If it is wildcard it goes in to the new variable.wildcardHostsadded. If we have we callapplyWildcardRuleswith the hosts and wildcard hosts.Hostvalues using regex in the form of^wildcard$where wildcard is theHostvalue with*replaced with.*.mergeSSHConfigs.nilon success andErrorotherwise.if/elseconditions and I try to not do that.TestMultiWildcard,TestUnmatchedWildcardBetween,TestUnmatchedWildcardPrefix,TestUnmatchedWildcardPost. Each of them tests a different placement of the wildcard and one of them tests multiple wildcards.TODO - Already addressed in latest commit.
LocalForwards,RemoteForwards,DynamicForwards- Currently we do not handle those. Might need to implement them specifically and not use reflection, must check. - ✔️Ciphers,MACs- First attempt at using reflection to add to a string array failed. Either read/try a bit more to make it work or do not use reflection, must check. - ✔️Includeed file, it will be applied only to hosts inside this include. - ✔️