|
39 | 39 | expect(credential.type).to eql 'plain' |
40 | 40 | end |
41 | 41 |
|
| 42 | + it 'should store `nil` passwords as an empty string' do |
| 43 | + subject.store_credentials 'foo', nil |
| 44 | + credential = Models::Credential.first |
| 45 | + expect(credential.password).to_not be_nil |
| 46 | + expect(credential.password).to eql '' |
| 47 | + end |
| 48 | + |
42 | 49 | context 'if a record with the same host + username + type already exists' do |
43 | 50 | context 'and the record is in the same workspace' do |
44 | 51 | context 'and has no password' do |
45 | 52 | it 'should overwrite the previous credential' do |
46 | | - subject.store_credentials 'foo', nil, 'test' |
| 53 | + subject.store_credentials 'foo', '', 'test' |
47 | 54 | subject.store_credentials 'foo', 'bar', 'test' |
48 | 55 | expect(Models::Credential.count).to eql 1 |
49 | 56 |
|
50 | 57 | credential = Models::Credential.first |
51 | 58 | expect(credential.password).to eql 'bar' |
52 | | - Models::Credential.truncate |
53 | | - |
54 | | - subject.store_credentials 'foo', 'bar', 'unique' |
55 | | - subject.store_credentials 'foo', 'foo', 'unique2' |
56 | | - expect(Models::Credential.count).to eql 2 |
57 | 59 | end |
58 | 60 | end |
59 | 61 |
|
60 | 62 | context 'and has a password' do |
61 | | - it 'should add a new entry' do |
62 | | - Models::Credential.create( |
63 | | - host: subject.target_host, |
64 | | - port: subject.target_port, |
65 | | - username: 'foo', |
66 | | - password: 'bar', |
67 | | - type: 'plain', |
68 | | - workspace: Models::Workspace.first(name: 'default') |
69 | | - ) |
| 63 | + context 'if the password is the same' do |
| 64 | + it 'should overwrite the previous credential' do |
| 65 | + subject.store_credentials 'foo', 'bar', 'test' |
| 66 | + subject.store_credentials 'foo', 'bar', 'test' |
| 67 | + expect(Models::Credential.count).to eql 1 |
| 68 | + end |
| 69 | + end |
70 | 70 |
|
71 | | - expect(Models::Credential.count).to eql 1 |
72 | | - subject.store_credentials 'foo', 'foo' |
73 | | - expect(Models::Credential.count).to eql 2 |
| 71 | + context 'if the new password is blank' do |
| 72 | + it 'should not overwrite the existing pasword' do |
| 73 | + subject.store_credentials 'foo', 'bar', 'test' |
| 74 | + subject.store_credentials 'foo', '', 'test' |
| 75 | + expect(Models::Credential.count).to eql 1 |
| 76 | + expect(Models::Credential.first.password).to eql 'bar' |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + context 'if the password is different' do |
| 81 | + it 'should add a new entry' do |
| 82 | + Models::Credential.create( |
| 83 | + host: subject.target_host, |
| 84 | + port: subject.target_port, |
| 85 | + username: 'foo', |
| 86 | + password: 'bar', |
| 87 | + type: 'plain', |
| 88 | + workspace: Models::Workspace.first(name: 'default') |
| 89 | + ) |
| 90 | + |
| 91 | + expect(Models::Credential.count).to eql 1 |
| 92 | + subject.store_credentials 'foo', 'foo' |
| 93 | + expect(Models::Credential.count).to eql 2 |
| 94 | + end |
74 | 95 | end |
75 | 96 | end |
76 | 97 | end |
|
0 commit comments