CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/support/shared/examples/msf/sessions.rb
Views: 11788
1
# frozen_string_literal: true
2
3
RSpec.shared_examples 'client session' do
4
subject(:session) do
5
session = described_class.new(nil, opts)
6
session.user_input = user_input
7
session.user_output = user_output
8
session.name = name
9
session
10
end
11
12
describe '.type' do
13
it 'should have the correct type' do
14
expect(described_class.type).to eq(type)
15
end
16
end
17
18
describe '.can_cleanup_files' do
19
it 'should be able to cleanup files' do
20
expect(described_class.can_cleanup_files).to eq(can_cleanup_files)
21
end
22
end
23
24
describe '#desc' do
25
it 'should have the correct description' do
26
expect(subject.desc).to eq(description)
27
end
28
end
29
30
describe '#type' do
31
it 'should have the correct type' do
32
expect(subject.type).to eq(type)
33
end
34
end
35
36
describe '#initialize' do
37
context 'without a client' do
38
let(:opts) { {} }
39
40
it 'raises a KeyError' do
41
expect { subject }.to raise_exception(KeyError)
42
end
43
end
44
context 'with a client' do
45
it 'does not raise an exception' do
46
expect { subject }.not_to raise_exception
47
end
48
end
49
50
it 'creates a new console' do
51
expect(subject.console).to be_a(console_class)
52
end
53
end
54
55
describe '#bootstrap' do
56
subject { session.bootstrap }
57
58
it 'keeps the sessions user input' do
59
expect { subject }.not_to change(session, :user_input).from(user_input)
60
end
61
62
it 'keeps the sessions user output' do
63
expect { subject }.not_to change(session, :user_output).from(user_output)
64
end
65
66
it 'sets the console input' do
67
expect { subject }.to change(session.console, :input).to(user_input)
68
end
69
70
it 'sets the console output' do
71
expect { subject }.to change(session.console, :output).to(user_output)
72
end
73
74
it 'sets the log source' do
75
expect { subject }.to change(session.console, :log_source).to(log_source)
76
end
77
end
78
79
describe '#reset_ui' do
80
before(:each) do
81
session.bootstrap
82
end
83
84
subject { session.reset_ui }
85
86
it 'keeps the sessions user input' do
87
expect { subject }.not_to change(session, :user_input).from(user_input)
88
end
89
90
it 'keeps the sessions user output' do
91
expect { subject }.not_to change(session, :user_output).from(user_output)
92
end
93
94
it 'resets the console input' do
95
expect { subject }.to change(session.console, :input).from(user_input).to(nil)
96
end
97
98
it 'resets the console output' do
99
expect { subject }.to change(session.console, :output).from(user_output).to(nil)
100
end
101
end
102
103
describe '#exit' do
104
subject { session.exit }
105
106
it 'exits the session' do
107
expect { subject }.to change(session.console, :stopped?).from(false).to(true)
108
end
109
end
110
111
describe '#address' do
112
subject { session.address }
113
114
it { is_expected.to eq(address) }
115
end
116
117
describe '#port' do
118
subject { session.port }
119
120
it { is_expected.to eq(port) }
121
end
122
end
123
124