|
476 | 476 | expect(id_token['auth_time']).to eq(auth_time) |
477 | 477 | end |
478 | 478 |
|
479 | | - it 'should fail when authorize params has organization but org_id is missing in the token' do |
480 | | - payload = { |
481 | | - iss: "https://#{domain}/", |
482 | | - sub: 'sub', |
483 | | - aud: client_id, |
484 | | - exp: future_timecode, |
485 | | - iat: past_timecode |
486 | | - } |
| 479 | + context 'Organization claim validation' do |
| 480 | + it 'should fail when authorize params has organization but org_id is missing in the token' do |
| 481 | + payload = { |
| 482 | + iss: "https://#{domain}/", |
| 483 | + sub: 'sub', |
| 484 | + aud: client_id, |
| 485 | + exp: future_timecode, |
| 486 | + iat: past_timecode |
| 487 | + } |
487 | 488 |
|
488 | | - token = make_hs256_token(payload) |
489 | | - expect do |
490 | | - jwt_validator.verify(token, { organization: 'Test Org' }) |
491 | | - end.to raise_error(an_instance_of(OmniAuth::Auth0::TokenValidationError).and having_attributes({ |
492 | | - message: "Organization Id (org_id) claim must be a string present in the ID token" |
493 | | - })) |
494 | | - end |
| 489 | + token = make_hs256_token(payload) |
| 490 | + expect do |
| 491 | + jwt_validator.verify(token, { organization: 'org_123' }) |
| 492 | + end.to raise_error(an_instance_of(OmniAuth::Auth0::TokenValidationError).and having_attributes({ |
| 493 | + message: "Organization Id (org_id) claim must be a string present in the ID token" |
| 494 | + })) |
| 495 | + end |
495 | 496 |
|
496 | | - it 'should fail when authorize params has organization but token org_id does not match' do |
497 | | - payload = { |
498 | | - iss: "https://#{domain}/", |
499 | | - sub: 'sub', |
500 | | - aud: client_id, |
501 | | - exp: future_timecode, |
502 | | - iat: past_timecode, |
503 | | - org_id: 'Wrong Org' |
504 | | - } |
| 497 | + it 'should fail when authorize params has organization but org_name is missing in the token' do |
| 498 | + payload = { |
| 499 | + iss: "https://#{domain}/", |
| 500 | + sub: 'sub', |
| 501 | + aud: client_id, |
| 502 | + exp: future_timecode, |
| 503 | + iat: past_timecode |
| 504 | + } |
505 | 505 |
|
506 | | - token = make_hs256_token(payload) |
507 | | - expect do |
508 | | - jwt_validator.verify(token, { organization: 'Test Org' }) |
509 | | - end.to raise_error(an_instance_of(OmniAuth::Auth0::TokenValidationError).and having_attributes({ |
510 | | - message: "Organization Id (org_id) claim value mismatch in the ID token; expected 'Test Org', found 'Wrong Org'" |
511 | | - })) |
512 | | - end |
| 506 | + token = make_hs256_token(payload) |
| 507 | + expect do |
| 508 | + jwt_validator.verify(token, { organization: 'my-organization' }) |
| 509 | + end.to raise_error(an_instance_of(OmniAuth::Auth0::TokenValidationError).and(having_attributes({ |
| 510 | + message: 'Organization Name (org_name) claim must be a string present in the ID token' |
| 511 | + }))) |
| 512 | + end |
513 | 513 |
|
| 514 | + it 'should fail when authorize params has organization but token org_id does not match' do |
| 515 | + payload = { |
| 516 | + iss: "https://#{domain}/", |
| 517 | + sub: 'sub', |
| 518 | + aud: client_id, |
| 519 | + exp: future_timecode, |
| 520 | + iat: past_timecode, |
| 521 | + org_id: 'org_5678' |
| 522 | + } |
| 523 | + |
| 524 | + token = make_hs256_token(payload) |
| 525 | + expect do |
| 526 | + jwt_validator.verify(token, { organization: 'org_1234' }) |
| 527 | + end.to raise_error(an_instance_of(OmniAuth::Auth0::TokenValidationError).and(having_attributes({ |
| 528 | + message: "Organization Id (org_id) claim value mismatch in the ID token; expected 'org_1234', found 'org_5678'" |
| 529 | + }))) |
| 530 | + end |
| 531 | + |
| 532 | + it 'should fail when authorize params has organization but token org_name does not match' do |
| 533 | + payload = { |
| 534 | + iss: "https://#{domain}/", |
| 535 | + sub: 'sub', |
| 536 | + aud: client_id, |
| 537 | + exp: future_timecode, |
| 538 | + iat: past_timecode, |
| 539 | + org_name: 'another-organization' |
| 540 | + } |
| 541 | + |
| 542 | + token = make_hs256_token(payload) |
| 543 | + expect do |
| 544 | + jwt_validator.verify(token, { organization: 'my-organization' }) |
| 545 | + end.to raise_error(an_instance_of(OmniAuth::Auth0::TokenValidationError).and(having_attributes({ |
| 546 | + message: "Organization Name (org_name) claim value mismatch in the ID token; expected 'my-organization', found 'another-organization'" |
| 547 | + }))) |
| 548 | + end |
| 549 | + |
| 550 | + it 'should not fail when correctly given an organization ID' do |
| 551 | + payload = { |
| 552 | + iss: "https://#{domain}/", |
| 553 | + sub: 'sub', |
| 554 | + aud: client_id, |
| 555 | + exp: future_timecode, |
| 556 | + iat: past_timecode, |
| 557 | + org_id: 'org_1234' |
| 558 | + } |
| 559 | + |
| 560 | + token = make_hs256_token(payload) |
| 561 | + jwt_validator.verify(token, { organization: 'org_1234' }) |
| 562 | + end |
| 563 | + |
| 564 | + it 'should not fail when correctly given an organization name' do |
| 565 | + payload = { |
| 566 | + iss: "https://#{domain}/", |
| 567 | + sub: 'sub', |
| 568 | + aud: client_id, |
| 569 | + exp: future_timecode, |
| 570 | + iat: past_timecode, |
| 571 | + org_name: 'my-organization' |
| 572 | + } |
| 573 | + |
| 574 | + token = make_hs256_token(payload) |
| 575 | + jwt_validator.verify(token, { organization: 'my-organization' }) |
| 576 | + end |
| 577 | + |
| 578 | + it 'should not fail when given an organization name in a different casing' do |
| 579 | + payload = { |
| 580 | + iss: "https://#{domain}/", |
| 581 | + sub: 'sub', |
| 582 | + aud: client_id, |
| 583 | + exp: future_timecode, |
| 584 | + iat: past_timecode, |
| 585 | + org_name: 'MY-ORGANIZATION' |
| 586 | + } |
| 587 | + |
| 588 | + token = make_hs256_token(payload) |
| 589 | + jwt_validator.verify(token, { organization: 'my-organization' }) |
| 590 | + end |
| 591 | + end |
514 | 592 | it 'should fail for RS256 token when kid is incorrect' do |
515 | 593 | domain = 'example.org' |
516 | 594 | sub = 'abc123' |
|
0 commit comments