hammer_cli_foreman 0.18.2 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/foreman.yml +20 -0
- data/doc/host_create.md +19 -10
- data/doc/release_notes.md +12 -4
- data/lib/hammer_cli_foreman/api/authenticator.rb +81 -0
- data/lib/hammer_cli_foreman/api/connection.rb +48 -33
- data/lib/hammer_cli_foreman/api/interactive_basic_auth.rb +2 -2
- data/lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb +100 -0
- data/lib/hammer_cli_foreman/api/oauth/password_grant.rb +81 -0
- data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +34 -80
- data/lib/hammer_cli_foreman/auth.rb +54 -20
- data/lib/hammer_cli_foreman/authenticate/login.rb +21 -0
- data/lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb +1 -0
- data/lib/hammer_cli_foreman/command_extensions/ping.rb +14 -0
- data/lib/hammer_cli_foreman/command_extensions/status.rb +44 -0
- data/lib/hammer_cli_foreman/command_extensions.rb +2 -0
- data/lib/hammer_cli_foreman/commands.rb +1 -1
- data/lib/hammer_cli_foreman/compute_attribute.rb +22 -5
- data/lib/hammer_cli_foreman/compute_resource/base.rb +1 -1
- data/lib/hammer_cli_foreman/compute_resource/ec2.rb +1 -1
- data/lib/hammer_cli_foreman/compute_resource/gce.rb +1 -1
- data/lib/hammer_cli_foreman/compute_resource/libvirt.rb +11 -8
- data/lib/hammer_cli_foreman/compute_resource/openstack.rb +1 -1
- data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +7 -4
- data/lib/hammer_cli_foreman/compute_resource/rackspace.rb +1 -1
- data/lib/hammer_cli_foreman/compute_resource/vmware.rb +6 -6
- data/lib/hammer_cli_foreman/hosts/common_update_options.rb +1 -1
- data/lib/hammer_cli_foreman/location.rb +1 -1
- data/lib/hammer_cli_foreman/openid_connect.rb +68 -0
- data/lib/hammer_cli_foreman/organization.rb +1 -1
- data/lib/hammer_cli_foreman/output/formatters.rb +4 -5
- data/lib/hammer_cli_foreman/partition_table.rb +1 -0
- data/lib/hammer_cli_foreman/ping.rb +24 -0
- data/lib/hammer_cli_foreman/report_template.rb +3 -2
- data/lib/hammer_cli_foreman/sessions.rb +92 -0
- data/lib/hammer_cli_foreman/status.rb +53 -0
- data/lib/hammer_cli_foreman/subnet.rb +1 -0
- data/lib/hammer_cli_foreman/template.rb +1 -0
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/lib/hammer_cli_foreman.rb +8 -0
- data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/test/data/1.24/foreman_api.json +1 -0
- data/test/data/README.md +2 -2
- data/test/functional/commands/list_test.rb +2 -2
- data/test/functional/host_test.rb +0 -20
- data/test/functional/ping_test.rb +34 -0
- data/test/functional/status_test.rb +46 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-CreateCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-InfoCommand-output.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-ListCommand-output.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-UpdateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Architecture.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-CommonParameter-DeleteCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-CommonParameter-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-CommonParameter-ListCommand-output.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-CommonParameter-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-CommonParameter-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-CommonParameter-SetCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-CommonParameter-SetCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-CommonParameter.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-CreateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-InfoCommand-output.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-ListCommand-output.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-UpdateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-ComputeResource.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-CreateCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-DeleteParameterCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-DeleteParameterCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-InfoCommand-output.xml +21 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-ListCommand-output.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-SetParameterCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-SetParameterCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-UpdateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Domain-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Domain.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-CreateCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-InfoCommand-output.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-ListCommand-output.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-UpdateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Environment-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Environment.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-ExceptionHandler.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Host-CreateCommand-parameters.xml +46 -0
- data/test/reports/TEST-HammerCLIForeman-Host-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Host-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Host-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Host-DeleteParameterCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Host-DeleteParameterCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Host-InfoCommand-output.xml +85 -0
- data/test/reports/TEST-HammerCLIForeman-Host-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Host-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Host-ListCommand-output.xml +21 -0
- data/test/reports/TEST-HammerCLIForeman-Host-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Host-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Host-PuppetRunCommand-output.xml +9 -0
- data/test/reports/TEST-HammerCLIForeman-Host-PuppetRunCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Host-SetParameterCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Host-SetParameterCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Host-StatusCommand-output.xml +9 -0
- data/test/reports/TEST-HammerCLIForeman-Host-StatusCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Host-UpdateCommand-parameters.xml +40 -0
- data/test/reports/TEST-HammerCLIForeman-Host-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Host.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-CreateCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteParameterCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteParameterCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-InfoCommand-output.xml +29 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-InfoCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-ListCommand-output.xml +27 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-SetParameterCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-SetParameterCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-UpdateCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Hostgroup.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Location-CreateCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Location-CreateCommand-resource-disabled.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Location-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Location-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Location-DeleteCommand-resource-disabled.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Location-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand-output.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand-resource-disabled.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Location-ListCommand-output.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Location-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Location-ListCommand-resource-disabled.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Location-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Location-UpdateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Location-UpdateCommand-resource-disabled.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Location-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Location.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-CreateCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-InfoCommand-output.xml +23 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-ListCommand-output.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-UpdateCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Medium-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Medium.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-CreateCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteParameterCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteParameterCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-InfoCommand-output.xml +27 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-ListCommand-output.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-SetParameterCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-SetParameterCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-UpdateCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-OperatingSystem.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-CreateCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-CreateCommand-resource-disabled.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-DeleteCommand-resource-disabled.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand-output.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand-resource-disabled.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand-output.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand-resource-disabled.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-UpdateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-UpdateCommand-resource-disabled.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Organization-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Organization.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-CreateCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-DumpCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-DumpCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-InfoCommand-output.xml +19 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-ListCommand-output.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-UpdateCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-PartitionTable.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-CreateCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-InfoCommand-output.xml +21 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-ListCommand-output.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-ListCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-UpdateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-SmartProxy.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-CreateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-DeleteCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-InfoCommand-output.xml +43 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-InfoCommand-parameters.xml +13 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-ListCommand-output.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-UpdateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Subnet.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Template-CreateCommand-parameters.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Template-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Template-DeleteCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Template-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Template-DumpCommand-parameters.xml +12 -0
- data/test/reports/TEST-HammerCLIForeman-Template-DumpCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Template-InfoCommand-output.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Template-InfoCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Template-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Template-ListCommand-output.xml +15 -0
- data/test/reports/TEST-HammerCLIForeman-Template-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-Template-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Template-ListKindsCommand-parameters.xml +9 -0
- data/test/reports/TEST-HammerCLIForeman-Template-ListKindsCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Template-UpdateCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-Template-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-Template.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-User-CreateCommand-parameters.xml +19 -0
- data/test/reports/TEST-HammerCLIForeman-User-CreateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-User-DeleteCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-User-DeleteCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-User-InfoCommand-output.xml +23 -0
- data/test/reports/TEST-HammerCLIForeman-User-InfoCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-User-InfoCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-User-ListCommand-output.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-User-ListCommand-parameters.xml +17 -0
- data/test/reports/TEST-HammerCLIForeman-User-ListCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-User-UpdateCommand-parameters.xml +11 -0
- data/test/reports/TEST-HammerCLIForeman-User-UpdateCommand.xml +7 -0
- data/test/reports/TEST-HammerCLIForeman-User.xml +7 -0
- data/test/reports/TEST-MiniTest-Spec.xml +7 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/api/interactive_basic_auth_test.rb +1 -1
- data/test/unit/api/oauth/oauth_authentication_code_grant_test.rb +88 -0
- data/test/unit/api/oauth/oauth_password_grant_test.rb +92 -0
- data/test/unit/api/session_authenticator_wrapper_test.rb +85 -70
- data/test/unit/sessions_test.rb +199 -0
- metadata +600 -81
@@ -21,54 +21,55 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
21
21
|
options[:dir_permissions] ||= 0700
|
22
22
|
options[:file_permissions] ||= 0600
|
23
23
|
options[:user_name] ||= 'admin'
|
24
|
+
options[:auth_type] ||= 'Basic_Auth'
|
24
25
|
|
25
|
-
out = err =
|
26
|
+
out = err = ''
|
26
27
|
|
27
28
|
dir = Dir.mktmpdir
|
28
29
|
begin
|
29
30
|
FileUtils.chmod(options[:dir_permissions], dir)
|
30
|
-
|
31
31
|
if options[:session_id]
|
32
|
-
session = JSON.dump(
|
33
|
-
:
|
34
|
-
:
|
35
|
-
|
32
|
+
session = JSON.dump(
|
33
|
+
id: options[:session_id],
|
34
|
+
user_name: options[:user_name],
|
35
|
+
auth_type: options[:auth_type]
|
36
|
+
)
|
36
37
|
write_session(dir, session, options[:file_permissions])
|
37
38
|
end
|
38
39
|
|
39
40
|
out, err = capture_io do
|
40
|
-
auth = HammerCLIForeman::Api::SessionAuthenticatorWrapper.new(
|
41
|
+
auth = HammerCLIForeman::Api::SessionAuthenticatorWrapper.new(
|
42
|
+
wrapped_auth, url, options[:auth_type]
|
43
|
+
)
|
44
|
+
HammerCLIForeman::Sessions.stubs(:storage).returns(dir)
|
45
|
+
HammerCLIForeman::Sessions.stubs(:enabled?).returns(true)
|
41
46
|
yield(auth, dir) if block_given?
|
42
47
|
end
|
43
48
|
ensure
|
44
49
|
FileUtils.remove_entry(dir)
|
45
50
|
end
|
46
|
-
|
47
51
|
return dir, out, err
|
48
52
|
end
|
49
53
|
|
50
|
-
describe '#
|
54
|
+
describe '#authenticate' do
|
51
55
|
context "when there's saved session" do
|
52
|
-
it '
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
it 'warns when session file has wrong permissions' do
|
60
|
-
dir, out, err = prepare_session_storage :session_id => 'SOME_SESSION_ID', :file_permissions => 0644
|
56
|
+
it 'sets session id in cookies for basic auth' do
|
57
|
+
session_params = {
|
58
|
+
session_id: 'SOME_SESSION_ID', auth_type: 'Basic_Auth'
|
59
|
+
}
|
60
|
+
prepare_session_storage session_params do |auth, dir|
|
61
|
+
wrapped_auth.stubs(:user).returns('admin')
|
62
|
+
auth.authenticate(request, args)
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
+
assert_equal '_session_id=SOME_SESSION_ID', request['Cookie']
|
65
|
+
end
|
64
66
|
end
|
65
|
-
end
|
66
|
-
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
it 'sets session id in cookies for oauth' do
|
69
|
+
session_params = {
|
70
|
+
session_id: 'SOME_SESSION_ID', auth_type: 'Oauth_Password_Grant'
|
71
|
+
}
|
72
|
+
prepare_session_storage session_params do |auth, dir|
|
72
73
|
wrapped_auth.expects(:user).returns('admin')
|
73
74
|
auth.authenticate(request, args)
|
74
75
|
|
@@ -77,7 +78,10 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
77
78
|
end
|
78
79
|
|
79
80
|
it 'ignores session when the session file has wrong permissions' do
|
80
|
-
|
81
|
+
session_params = {
|
82
|
+
:session_id => 'SOME_SESSION_ID', :file_permissions => 0644
|
83
|
+
}
|
84
|
+
prepare_session_storage session_params do |auth, dir|
|
81
85
|
wrapped_auth.expects(:authenticate).with(request, args)
|
82
86
|
wrapped_auth.expects(:user).returns('admin')
|
83
87
|
auth.authenticate(request, args)
|
@@ -87,7 +91,10 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
87
91
|
end
|
88
92
|
|
89
93
|
it 'ignores session when the directory has wrong permissions' do
|
90
|
-
|
94
|
+
session_params = {
|
95
|
+
:session_id => 'SOME_SESSION_ID', :dir_permissions => 0744
|
96
|
+
}
|
97
|
+
prepare_session_storage session_params do |auth, dir|
|
91
98
|
wrapped_auth.expects(:authenticate).with(request, args)
|
92
99
|
wrapped_auth.expects(:user).returns('admin')
|
93
100
|
auth.authenticate(request, args)
|
@@ -96,7 +103,7 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
96
103
|
end
|
97
104
|
end
|
98
105
|
|
99
|
-
it "keeps the session and sets
|
106
|
+
it "keeps the session and sets user_changed flag when usernames don't match" do
|
100
107
|
prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
|
101
108
|
wrapped_auth.expects(:authenticate).with(request, args)
|
102
109
|
wrapped_auth.expects(:user).returns('other_user')
|
@@ -107,12 +114,26 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
107
114
|
end
|
108
115
|
end
|
109
116
|
|
110
|
-
it "keeps the session when
|
117
|
+
it "keeps the session and sets cuser_changed flag when usernames don't match for Oauth" do
|
118
|
+
session_params = {
|
119
|
+
:session_id => 'SOME_SESSION_ID', :auth_type => 'Oauth_Password_Grant'
|
120
|
+
}
|
121
|
+
prepare_session_storage session_params do |auth, dir|
|
122
|
+
wrapped_auth.expects(:authenticate).with(request, args)
|
123
|
+
wrapped_auth.expects(:user).returns('other_user')
|
124
|
+
auth.authenticate(request, args)
|
125
|
+
|
126
|
+
assert File.exist?(session_file(dir))
|
127
|
+
assert auth.user_changed?
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'keeps the session when username is nil' do
|
111
132
|
prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
|
112
133
|
wrapped_auth.expects(:user).returns(nil)
|
113
134
|
auth.authenticate(request, args)
|
114
135
|
|
115
|
-
assert_equal
|
136
|
+
assert_equal '_session_id=SOME_SESSION_ID', request['Cookie']
|
116
137
|
assert File.exist?(session_file(dir))
|
117
138
|
end
|
118
139
|
end
|
@@ -127,20 +148,7 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
127
148
|
wrapped_auth.expects(:user).returns('admin')
|
128
149
|
auth.authenticate(request, args)
|
129
150
|
end
|
130
|
-
|
131
|
-
assert_match /Invalid session file format/, err
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'deletes the session file' do
|
135
|
-
prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
|
136
|
-
write_session(dir, '{not a valid: json')
|
137
|
-
|
138
|
-
wrapped_auth.expects(:authenticate).with(request, args)
|
139
|
-
wrapped_auth.expects(:user).returns('admin')
|
140
|
-
auth.authenticate(request, args)
|
141
|
-
|
142
|
-
refute File.exist?(session_file(dir))
|
143
|
-
end
|
151
|
+
assert_match "Invalid session data. Resetting the session.\n", err
|
144
152
|
end
|
145
153
|
end
|
146
154
|
|
@@ -157,13 +165,13 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
157
165
|
|
158
166
|
describe '#error' do
|
159
167
|
context 'when there is existing session' do
|
160
|
-
it '
|
168
|
+
it 'sets session id to nil on unauthorized exception' do
|
161
169
|
prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
|
162
170
|
ex = RestClient::Unauthorized.new
|
163
|
-
|
164
171
|
auth.error(ex)
|
165
172
|
|
166
|
-
|
173
|
+
assert_nil auth.session.id
|
174
|
+
assert File.exist?(session_file(dir))
|
167
175
|
end
|
168
176
|
end
|
169
177
|
|
@@ -245,35 +253,28 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
245
253
|
it "saves session id if it's in response cookies" do
|
246
254
|
prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
|
247
255
|
resp = stub(:cookies => {'_session_id' => 'NEW_SESSION_ID'}, :code => 200)
|
248
|
-
|
249
256
|
wrapped_auth.expects(:response).with(resp)
|
250
257
|
wrapped_auth.expects(:user).returns('admin')
|
251
258
|
auth.response(resp)
|
252
259
|
|
253
|
-
|
254
|
-
|
255
|
-
assert_equal 'NEW_SESSION_ID', session['session_id']
|
260
|
+
assert_equal 'NEW_SESSION_ID', auth.session.id
|
256
261
|
end
|
257
262
|
end
|
258
263
|
|
259
|
-
it
|
264
|
+
it 'saves username' do
|
260
265
|
prepare_session_storage do |auth, dir|
|
261
266
|
resp = stub(:cookies => {'_session_id' => 'NEW_SESSION_ID'}, :code => 200)
|
262
|
-
|
263
267
|
wrapped_auth.expects(:response).with(resp)
|
264
268
|
wrapped_auth.expects(:user).returns('admin')
|
265
269
|
auth.response(resp)
|
266
270
|
|
267
|
-
|
268
|
-
|
269
|
-
assert_equal 'admin', session['user_name']
|
271
|
+
assert_equal 'admin', auth.session.user_name
|
270
272
|
end
|
271
273
|
end
|
272
274
|
|
273
|
-
it
|
275
|
+
it 'ignores requests without session cookie' do
|
274
276
|
prepare_session_storage do |auth, dir|
|
275
277
|
resp = stub(:cookies => {}, :code => 200)
|
276
|
-
|
277
278
|
wrapped_auth.expects(:response).with(resp)
|
278
279
|
auth.response(resp)
|
279
280
|
|
@@ -281,7 +282,7 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
281
282
|
end
|
282
283
|
end
|
283
284
|
|
284
|
-
it
|
285
|
+
it 'ignores unauthorized requests' do
|
285
286
|
prepare_session_storage do |auth, dir|
|
286
287
|
resp = stub(:cookies => {'_session_id' => 'NEW_SESSION_ID'}, :code => 401)
|
287
288
|
|
@@ -289,7 +290,6 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
289
290
|
auth.response(resp)
|
290
291
|
|
291
292
|
refute File.exist?(session_file(dir))
|
292
|
-
assert_nil auth.session_id
|
293
293
|
end
|
294
294
|
end
|
295
295
|
end
|
@@ -301,7 +301,7 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
301
301
|
end
|
302
302
|
end
|
303
303
|
|
304
|
-
it
|
304
|
+
it 'calls #user on the wrapped authentocator' do
|
305
305
|
prepare_session_storage do |auth, dir|
|
306
306
|
wrapped_auth.expects(:user).returns('admin')
|
307
307
|
assert_equal 'admin', auth.user
|
@@ -326,17 +326,32 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
326
326
|
end
|
327
327
|
end
|
328
328
|
|
329
|
-
describe '#
|
329
|
+
describe '#set_auth_params' do
|
330
330
|
it 'passes credentials to a wrapped authenticator' do
|
331
|
-
prepare_session_storage do |auth, dir|
|
331
|
+
prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
|
332
332
|
wrapped_auth.expects(:set_credentials).with('admin', 'password')
|
333
|
-
auth.
|
333
|
+
auth.set_auth_params('admin', 'password')
|
334
334
|
end
|
335
335
|
end
|
336
336
|
|
337
|
-
it
|
338
|
-
prepare_session_storage do |auth, dir|
|
339
|
-
|
337
|
+
it 'passes credentials to a wrapped authenticator' do
|
338
|
+
prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
|
339
|
+
wrapped_auth.expects(:set_credentials).with('admin', 'password')
|
340
|
+
auth.set_auth_params('admin', 'password')
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'passes credentials to a wrapped authenticator' do
|
345
|
+
prepare_session_storage :session_id => 'SOME_SESSION_ID', :auth_type => 'Oauth_Password_Grant' do |auth, dir|
|
346
|
+
wrapped_auth.expects(:set_token).with('admin', 'password')
|
347
|
+
auth.set_auth_params('admin', 'password')
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'passes credentials to a wrapped authenticator' do
|
352
|
+
prepare_session_storage :session_id => 'SOME_SESSION_ID', :auth_type => 'Oauth_Authentication_Code_Grant' do |auth, dir|
|
353
|
+
wrapped_auth.expects(:set_token).with('admin', 'password')
|
354
|
+
auth.set_auth_params('admin', 'password')
|
340
355
|
end
|
341
356
|
end
|
342
357
|
end
|
@@ -359,11 +374,11 @@ describe HammerCLIForeman::Api::SessionAuthenticatorWrapper do
|
|
359
374
|
describe '#status' do
|
360
375
|
it 'informs that there is no existing session' do
|
361
376
|
prepare_session_storage do |auth, dir|
|
362
|
-
assert_equal
|
377
|
+
assert_equal 'Using sessions, you are currently not logged in.', auth.status
|
363
378
|
end
|
364
379
|
end
|
365
380
|
|
366
|
-
it
|
381
|
+
it 'informs about existing session' do
|
367
382
|
prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
|
368
383
|
assert_equal "Session exists, currently logged in as 'admin'.", auth.status
|
369
384
|
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
require 'hammer_cli_foreman/sessions'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
describe HammerCLIForeman do
|
8
|
+
describe HammerCLIForeman::Sessions do
|
9
|
+
describe "#get" do
|
10
|
+
it 'should create session file when it doesn\'t exist' do
|
11
|
+
HammerCLI::Settings.expects(:get).with(:foreman, :use_sessions).returns(true)
|
12
|
+
Dir.mktmpdir do |dir|
|
13
|
+
HammerCLIForeman::Sessions.stubs(:storage).returns(dir)
|
14
|
+
session = HammerCLIForeman::Sessions.get('http://example.com')
|
15
|
+
session.id.must_be_nil
|
16
|
+
session.auth_type.must_be_nil
|
17
|
+
session.user_name.must_be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should load the session file' do
|
22
|
+
HammerCLI::Settings.expects(:get).with(:foreman, :use_sessions).returns(true)
|
23
|
+
Dir.mktmpdir do |dir|
|
24
|
+
HammerCLIForeman::Sessions.stubs(:storage).returns(dir)
|
25
|
+
session_content = {
|
26
|
+
:id => '3040b0f04c3a35a499e6837278904d48',
|
27
|
+
:user_name => 'admin',
|
28
|
+
:auth_type => 'basic_auth'
|
29
|
+
}
|
30
|
+
session_path = "#{dir}/http_example.com"
|
31
|
+
File.open(session_path,"w") do |f|
|
32
|
+
f.write(session_content.to_json)
|
33
|
+
end
|
34
|
+
File.chmod(0600, session_path)
|
35
|
+
|
36
|
+
session = HammerCLIForeman::Sessions.get('http://example.com')
|
37
|
+
session.id.must_equal '3040b0f04c3a35a499e6837278904d48'
|
38
|
+
session.auth_type.must_equal 'basic_auth'
|
39
|
+
session.user_name.must_equal 'admin'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should create the storage dir if it does not exist' do
|
44
|
+
HammerCLI::Settings.expects(:get).with(:foreman, :use_sessions).returns(true)
|
45
|
+
Dir.mktmpdir do |dir|
|
46
|
+
HammerCLIForeman::Sessions.stubs(:storage).returns(dir)
|
47
|
+
FileUtils.rm_rf(dir)
|
48
|
+
HammerCLIForeman::Sessions.get('http://example.com')
|
49
|
+
File.exist?(dir).must_equal true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should check permissions (700) on the storage' do
|
54
|
+
HammerCLI::Settings.expects(:get).with(:foreman, :use_sessions).returns(true)
|
55
|
+
Dir.mktmpdir do |dir|
|
56
|
+
HammerCLIForeman::Sessions.stubs(:storage).returns(dir)
|
57
|
+
FileUtils.chmod(0777, dir)
|
58
|
+
_, err = capture_io { HammerCLIForeman::Sessions.get('http://example.com') }
|
59
|
+
err.must_equal("Invalid permissions for #{dir}: 40777, expected 40700.\n" \
|
60
|
+
"Using session auth with invalid permissions on session files is not recommended.\n")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should check permissions (600) on the storage file' do
|
65
|
+
HammerCLI::Settings.expects(:get).with(:foreman, :use_sessions).returns(true)
|
66
|
+
Dir.mktmpdir do |dir|
|
67
|
+
HammerCLIForeman::Sessions.stubs(:storage).returns(dir)
|
68
|
+
session_content = {
|
69
|
+
:id => '3040b0f04c3a35a499e6837278904d48',
|
70
|
+
:user_name => 'admin',
|
71
|
+
:auth_type => 'basic_auth'
|
72
|
+
}
|
73
|
+
session_path = "#{dir}/http_example.com"
|
74
|
+
File.open(session_path,"w") do |f|
|
75
|
+
f.write(session_content.to_json)
|
76
|
+
end
|
77
|
+
File.chmod(0666, session_path)
|
78
|
+
|
79
|
+
_, err = capture_io { HammerCLIForeman::Sessions.get('http://example.com') }
|
80
|
+
err.must_equal("Invalid permissions for #{session_path}: 100666, expected 100600.\n" \
|
81
|
+
"Using session auth with invalid permissions on session files is not recommended.\n")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should fail if sessions are not enabled' do
|
86
|
+
HammerCLI::Settings.expects(:get).with(:foreman, :use_sessions).returns(false)
|
87
|
+
e = proc { HammerCLIForeman::Sessions.get('http://example.com')}.must_raise RuntimeError
|
88
|
+
e.message.must_equal "Sessions are not enabled, please check your Hammer settings."
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#enabled?" do
|
93
|
+
it 'tests sessions are enabled' do
|
94
|
+
HammerCLI::Settings.expects(:get).with(:foreman, :use_sessions).returns(true)
|
95
|
+
HammerCLIForeman::Sessions.enabled?.must_equal true
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'tests sessions are disabled' do
|
99
|
+
HammerCLI::Settings.expects(:get).with(:foreman, :use_sessions).returns(false)
|
100
|
+
HammerCLIForeman::Sessions.enabled?.must_equal false
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#session_file" do
|
105
|
+
it 'should return file path for session' do
|
106
|
+
file_path = HammerCLIForeman::Sessions.session_file('http://example.com')
|
107
|
+
file_path.must_equal(File.join(HammerCLIForeman::Sessions.storage, 'http_example.com'))
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should handle invalid url' do
|
111
|
+
e = proc { HammerCLIForeman::Sessions.session_file('/\/')}.must_raise RuntimeError
|
112
|
+
e.message.must_equal "The url (/\\/) is not a valid URL. Session can not be created."
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should handle empty url' do
|
116
|
+
e = proc { HammerCLIForeman::Sessions.session_file('')}.must_raise RuntimeError
|
117
|
+
e.message.must_equal "The url is empty. Session can not be created."
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe HammerCLIForeman::Session do
|
123
|
+
it 'should be able to store its data' do
|
124
|
+
Tempfile.create('session') do |f|
|
125
|
+
session = HammerCLIForeman::Session.new(f.path)
|
126
|
+
session.id = '3040b0f04c3a35a499e6837278904d48'
|
127
|
+
session.auth_type = 'basic_auth'
|
128
|
+
session.user_name = 'admin'
|
129
|
+
session.store
|
130
|
+
|
131
|
+
session = HammerCLIForeman::Session.new(f.path)
|
132
|
+
session.id.must_equal '3040b0f04c3a35a499e6837278904d48'
|
133
|
+
session.auth_type.must_equal 'basic_auth'
|
134
|
+
session.user_name.must_equal 'admin'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should store session file with 600 perm' do
|
139
|
+
Tempfile.create('session') do |f|
|
140
|
+
session = HammerCLIForeman::Session.new(f.path)
|
141
|
+
session.store
|
142
|
+
File.stat(f.path).mode.to_s(8).must_equal '100600'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should reset invalid session file' do
|
147
|
+
Tempfile.create('session') do |f|
|
148
|
+
f << '{[Invalid'
|
149
|
+
f.rewind
|
150
|
+
_, err = capture_io do
|
151
|
+
session = HammerCLIForeman::Session.new(f.path)
|
152
|
+
session.id = nil
|
153
|
+
session.auth_type = nil
|
154
|
+
session.user_name = nil
|
155
|
+
end
|
156
|
+
err.must_equal("Invalid session data. Resetting the session.\n")
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe ".destroy" do
|
161
|
+
it 'should be able to destroy session' do
|
162
|
+
Tempfile.create('session') do |f|
|
163
|
+
session = HammerCLIForeman::Session.new(f.path)
|
164
|
+
session.id = '3040b0f04c3a35a499e6837278904d48'
|
165
|
+
session.auth_type = 'basic_auth'
|
166
|
+
session.user_name = 'admin'
|
167
|
+
session.destroy
|
168
|
+
|
169
|
+
session = HammerCLIForeman::Session.new(f.path)
|
170
|
+
session.id.must_be_nil
|
171
|
+
session.auth_type.must_equal 'basic_auth'
|
172
|
+
session.user_name.must_equal 'admin'
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe ".valid?" do
|
178
|
+
it "tests if session is invalid" do
|
179
|
+
Tempfile.create('session') do |f|
|
180
|
+
session = HammerCLIForeman::Session.new(f.path)
|
181
|
+
session.id = nil
|
182
|
+
session.auth_type = 'basic_auth'
|
183
|
+
session.user_name = 'admin'
|
184
|
+
session.valid?.must_equal false
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
it "tests if session is valid" do
|
189
|
+
Tempfile.create('session') do |f|
|
190
|
+
session = HammerCLIForeman::Session.new(f.path)
|
191
|
+
session.id = '34252624635723572357234'
|
192
|
+
session.auth_type = 'basic_auth'
|
193
|
+
session.user_name = 'admin'
|
194
|
+
session.valid?.must_equal true
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|