Back to Repositories

Validating API Token Management Implementation in DocuSeal

This test suite validates API settings functionality in the DocuSeal application, focusing on user authentication and token management. It ensures proper display and security of API access tokens through system-level testing.

Test Coverage Overview

The test suite covers essential API settings functionality with focus on access token display and security.

  • Validates API settings page accessibility
  • Tests authentication token masking
  • Verifies proper user session handling
  • Ensures secure token display format

Implementation Analysis

The implementation uses RSpec system tests to simulate user interactions with the API settings interface. It leverages factory-based test data generation and session management to validate the API token display functionality.

The test employs sign-in helpers and page object patterns, utilizing RSpec’s expectation syntax for assertions about page content and form fields.

Technical Details

  • RSpec for test framework
  • FactoryBot for test data generation
  • Capybara for page interaction
  • Rails helper integration
  • Session management helpers
  • Page object patterns

Best Practices Demonstrated

The test suite demonstrates several testing best practices for API-related functionality.

  • Proper test isolation using let! blocks
  • Clear setup and expectations structure
  • Security-conscious token masking verification
  • Efficient test data management
  • Focused test scope

docusealco/docuseal

spec/system/api_settings_spec.rb

            
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'API Settings' do
  let!(:account) { create(:account) }
  let!(:user) { create(:user, account:) }

  before do
    sign_in(user)
    visit settings_api_index_path
  end

  it 'shows verify signed PDF page' do
    expect(page).to have_content('API')
    token = user.access_token.token
    expect(page).to have_field('X-Auth-Token', with: token.sub(token[5..], '*' * token[5..].size))
  end
end