Skip to content

Commit f82483b

Browse files
committed
TeamCity: Initial TeamCity Crypto tests
1 parent 970beb4 commit f82483b

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
require 'rspec'
2+
require 'metasploit/framework/login_scanner/teamcity'
3+
4+
RSpec.describe Metasploit::Framework::LoginScanner::Teamcity do
5+
6+
let(:subject) { described_class.new }
7+
8+
# Sample public key taken from a running instance of TeamCity
9+
let(:teamcity_public_key) { 123745099044379560034534292817206769690406658656179033915532150868201038268331364602421054634661908195221281696003927960251442559477403753250293468778385622756011022439279250077496033565623853604577886813851441780820332383679913126402116420846511593354558582754642561605875011841424796003363034584971880190853 }
10+
11+
describe '#two_byte_chars?' do
12+
[
13+
{ input: 'abc', expected: false },
14+
{ input: '', expected: false },
15+
{ input: 'ççç', expected: true },
16+
{ input: 'メタスプライトが大好きです', expected: true } # I love metasploit
17+
].each do |scenario|
18+
it 'returns the correct value' do
19+
expect(subject.two_byte_chars?(scenario[:input])).to eq(scenario[:expected])
20+
end
21+
end
22+
23+
[
24+
{ input: nil },
25+
{ input: true },
26+
{ input: 123 },
27+
{ input: [] }
28+
].each do |scenario|
29+
it 'raises an error on incorrect type' do
30+
expect { subject.two_byte_chars?(scenario[:input]) }.to raise_error(ArgumentError)
31+
end
32+
end
33+
end
34+
35+
describe '#max_data_size' do
36+
[
37+
{ input: 'abc', expected: 116 },
38+
{ input: '', expected: 116 },
39+
{ input: 'ççç', expected: 58 }, # TODO: In the browser, this is reported as 118.
40+
{ input: 'メタスプライトが大好きです', expected: 58 } # I love metasploit
41+
].each do |scenario|
42+
it 'returns the correct maximum message length' do
43+
expect(subject.max_data_size(scenario[:input])).to eq(scenario[:expected])
44+
end
45+
end
46+
47+
[
48+
{ input: nil },
49+
{ input: true },
50+
{ input: 123 },
51+
{ input: [] }
52+
].each do |scenario|
53+
it 'raises an error on incorrect type' do
54+
expect { subject.max_data_size(scenario[:input]) }.to raise_error(ArgumentError)
55+
end
56+
end
57+
end
58+
59+
describe '#pkcs1pad2' do
60+
[
61+
{ input: 'abc', expected: '0061626303' },
62+
{ input: '', expected: '0000' },
63+
{ input: 'ççç', expected: '00e7e7e703' }, # 3 chars, E7 codepoint
64+
{ input: 'メタスプライトが大好きです', expected: '0030e130bf30b930d730e930a430c8304c5927597d304d3067305913' } # I love metasploit
65+
].each do |scenario|
66+
it 'correctly pads text' do
67+
n = (teamcity_public_key.bit_length + 7) >> 3
68+
padded_as_big_int = subject.pkcs1pad2(scenario[:input], n)
69+
padded_hex = padded_as_big_int.to_s(16)
70+
expect(padded_hex.end_with?(scenario[:expected])).to eql(true)
71+
end
72+
end
73+
74+
[
75+
{ input: nil, n: nil },
76+
{ input: '', n: nil },
77+
{ input: nil, n: 128 },
78+
{ input: true, n: true },
79+
].each do |scenario|
80+
it 'raises an error on incorrect type' do
81+
expect { subject.pkcs1pad2(scenario[:input], scenario[:n]) }.to raise_error(ArgumentError)
82+
end
83+
end
84+
85+
[
86+
{ input: 'a', n: 11 },
87+
{ input: 'very_long_message_that_consists_of_many_characters', n: 40 }
88+
].each do |scenario|
89+
it 'raises an error when message is too long' do
90+
expect { subject.pkcs1pad2(scenario[:input], scenario[:n]) }.to raise_error(ArgumentError)
91+
end
92+
end
93+
end
94+
end

0 commit comments

Comments
 (0)