blob: 24bc42f9bf40fe5ba2a89e117bac844dca5cb939 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
# single user test server.
# You obviously want sth. different for real life.
class Server
attr_accessor :salt, :verifier, :username
def initialize(salt, verifier, username)
@salt = salt
@verifier = verifier
@username = username
end
def handshake(login, aa)
# this can be serialized and needs to be persisted between requests
@session = SRP::Session.new(self, aa)
return @session.bb
end
def validate(m)
@session.authenticate(m)
end
end
class AuthTest < Test::Unit::TestCase
def setup
@username = 'user'
@password = 'opensesami'
@client = SRP::Client.new(@username, @password)
@server = Server.new(@client.salt, @client.verifier, @username)
end
def test_successful_auth
assert @client.authenticate(@server)
end
def test_a_wrong_password
client = SRP::Client.new(@username, "wrong password", @client.salt)
assert !client.authenticate(@server)
end
def test_wrong_username
client = SRP::Client.new("wrong username", @password, @client.salt)
assert !client.authenticate(@server)
end
end
|