|
| 1 | + |
| 2 | +RSpec.describe KeycloakAdmin::CredentialRepresentation do |
| 3 | + describe ".from_json" do |
| 4 | + it "parses a password" do |
| 5 | + json_payload = <<-'payload' |
| 6 | + { |
| 7 | + "id": "2ff4b4d0-fd72-4c6e-9684-02ab337687c2", |
| 8 | + "type": "password", |
| 9 | + "userLabel": "My password", |
| 10 | + "createdDate": 1767604673211, |
| 11 | + "credentialData": "{\"hashIterations\":5,\"algorithm\":\"argon2\",\"additionalParameters\":{\"hashLength\":[\"32\"],\"memory\":[\"7168\"],\"type\":[\"id\"],\"version\":[\"1.3\"],\"parallelism\":[\"1\"]}}" |
| 12 | + } |
| 13 | + payload |
| 14 | + |
| 15 | + credential = described_class.from_json(json_payload) |
| 16 | + expect(credential).to be |
| 17 | + expect(credential).to be_a described_class |
| 18 | + expect(credential.id).to eq "2ff4b4d0-fd72-4c6e-9684-02ab337687c2" |
| 19 | + expect(credential.type).to eq "password" |
| 20 | + expect(credential.createdDate).to eq 1767604673211 |
| 21 | + expect(credential.credentialData).to eq "{\"hashIterations\":5,\"algorithm\":\"argon2\",\"additionalParameters\":{\"hashLength\":[\"32\"],\"memory\":[\"7168\"],\"type\":[\"id\"],\"version\":[\"1.3\"],\"parallelism\":[\"1\"]}}" |
| 22 | + expect(credential.userLabel).to eq "My password" |
| 23 | + expect(credential.device).to be_nil |
| 24 | + expect(credential.value).to be_nil |
| 25 | + expect(credential.hashedSaltedValue).to be_nil |
| 26 | + expect(credential.salt).to be_nil |
| 27 | + expect(credential.hashIterations).to eq 5 |
| 28 | + expect(credential.counter).to be_nil |
| 29 | + expect(credential.algorithm).to eq "argon2" |
| 30 | + expect(credential.digits).to be_nil |
| 31 | + expect(credential.period).to be_nil |
| 32 | + expect(credential.config).to be_nil |
| 33 | + expect(credential.temporary).to be_nil |
| 34 | + end |
| 35 | + |
| 36 | + it "parses an otp" do |
| 37 | + json_payload = <<-'payload' |
| 38 | + { |
| 39 | + "id": "34389672-9356-4154-9ed6-6c212b869010", |
| 40 | + "type": "otp", |
| 41 | + "userLabel": "Smartphone", |
| 42 | + "createdDate": 1767605202060, |
| 43 | + "credentialData": "{\"subType\":\"totp\",\"digits\":6,\"counter\":0,\"period\":30,\"algorithm\":\"HmacSHA1\"}" |
| 44 | + } |
| 45 | + payload |
| 46 | + |
| 47 | + credential = described_class.from_json(json_payload) |
| 48 | + expect(credential).to be |
| 49 | + expect(credential).to be_a described_class |
| 50 | + expect(credential.id).to eq "34389672-9356-4154-9ed6-6c212b869010" |
| 51 | + expect(credential.type).to eq "otp" |
| 52 | + expect(credential.createdDate).to eq 1767605202060 |
| 53 | + expect(credential.credentialData).to eq "{\"subType\":\"totp\",\"digits\":6,\"counter\":0,\"period\":30,\"algorithm\":\"HmacSHA1\"}" |
| 54 | + expect(credential.userLabel).to eq "Smartphone" |
| 55 | + expect(credential.device).to be_nil |
| 56 | + expect(credential.value).to be_nil |
| 57 | + expect(credential.hashedSaltedValue).to be_nil |
| 58 | + expect(credential.salt).to be_nil |
| 59 | + expect(credential.hashIterations).to be_nil |
| 60 | + expect(credential.counter).to eq 0 |
| 61 | + expect(credential.algorithm).to eq "HmacSHA1" |
| 62 | + expect(credential.digits).to eq 6 |
| 63 | + expect(credential.period).to eq 30 |
| 64 | + expect(credential.config).to be_nil |
| 65 | + expect(credential.temporary).to be_nil |
| 66 | + end |
| 67 | + end |
| 68 | +end |
0 commit comments