Skip to content

Commit

Permalink
Add auth providers config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyiliev committed May 11, 2024
1 parent 671e210 commit e3e59cd
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 88 deletions.
93 changes: 46 additions & 47 deletions resources/views/pages/auth/setup/providers.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,56 +29,55 @@ public function update($slug, $checked){
?>

<x-auth::layouts.setup>
<div>
<x-auth::layouts.setup>

@volt('auth.setup.providers')
<section class="relative px-4 py-5 mx-auto w-full max-w-screen-lg">
<x-auth::setup.full-screen-loader wire:target="update" />
<x-auth::setup.heading title="Social Providers" description="Select the social networks that users can use for authentication" />
<div class="relative w-full">
@if(!file_exists(base_path('config/devdojo/auth/providers.php')))
<x-auth::setup.config-notification />
@else
<div class="grid grid-cols-2">
@foreach($this->providers as $network_slug => $provider)

<div class="flex relative justify-between items-center max-w-sm border-b border-b-zinc-200">
<div class="flex relative justify-start items-center py-5 space-x-3">
<div class="flex items-center space-x-3">
<div class="w-7 h-7">
@if(isset($provider['svg']) && !empty(trim($provider['svg'])))
{!! $provider['svg'] !!}
@volt('auth.setup.providers')
<section class="relative px-4 py-5 mx-auto w-full max-w-screen-lg">
<x-auth::setup.full-screen-loader wire:target="update" />
<x-auth::setup.heading title="Social Providers" description="Select the social networks that users can use for authentication" />
<div class="relative w-full">
@if(!file_exists(base_path('config/devdojo/auth/providers.php')))
<x-auth::setup.config-notification />
@else
<div class="grid grid-cols-2">
@foreach($this->providers as $network_slug => $provider)

<div class="flex relative justify-between items-center max-w-sm border-b border-b-zinc-200">
<div class="flex relative justify-start items-center py-5 space-x-3">
<div class="flex items-center space-x-3">
<div class="w-7 h-7">
@if(isset($provider['svg']) && !empty(trim($provider['svg'])))
{!! $provider['svg'] !!}
@else
<span class="block w-full h-full rounded-full bg-zinc-200"></span>
@endif
</div>
<div class="relative">
<h4 class="text-base font-bold">{{ $provider['name'] }}</h4>
<p class="hidden text-sm">slug: {{ $network_slug }}</p>
</div>
</div>
<div class="relative right">
@if(isset($provider['client_id']) && !empty(trim($provider['client_id'])) && isset($provider['client_secret']) && !empty(trim($provider['client_secret'])))
<span x-tooltip="Keys have been added" class="flex justify-center items-center w-7 h-7 text-green-500 bg-green-100 rounded-full">
<x-phosphor-key-duotone class="w-4 h-4 text-green-500" />
<span>
@else
<span class="block w-full h-full rounded-full bg-zinc-200"></span>
<span x-tooltip="Missing keys for {{ strtoupper($network_slug) }}_CLIENT_ID and {{ strtoupper($network_slug) }}_CLIENT_SECRET inside your .env" class="flex justify-center items-center w-7 h-7 text-red-500 bg-red-100 rounded-full border-red-200">
<x-phosphor-key-duotone class="w-4 h-4 text-red-500" />
<span>
@endif
</div>
<div class="relative">
<h4 class="text-base font-bold">{{ $provider['name'] }}</h4>
<p class="hidden text-sm">slug: {{ $network_slug }}</p>
</div>
</div>
</div>
<div class="relative right">
@if(isset($provider['client_id']) && !empty(trim($provider['client_id'])) && isset($provider['client_secret']) && !empty(trim($provider['client_secret'])))
<span x-tooltip="Keys have been added" class="flex justify-center items-center w-7 h-7 text-green-500 bg-green-100 rounded-full">
<x-phosphor-key-duotone class="w-4 h-4 text-green-500" />
<span>
@else
<span x-tooltip="Missing keys for {{ strtoupper($network_slug) }}_CLIENT_ID and {{ strtoupper($network_slug) }}_CLIENT_SECRET inside your .env" class="flex justify-center items-center w-7 h-7 text-red-500 bg-red-100 rounded-full border-red-200">
<x-phosphor-key-duotone class="w-4 h-4 text-red-500" />
<span>
@endif
</div>
<x-auth::setup.checkbox wire:change="update('{{ $network_slug }}', $el.checked)" :checked="($provider['active'] ? true : false)" />
</div>
<x-auth::setup.checkbox wire:change="update('{{ $network_slug }}', $el.checked)" :checked="($provider['active'] ? true : false)" />
</div>
@endforeach
</div>
@endif
</div>
</section>
@endvolt

</x-auth::layouts.setup>


@endforeach
</div>
@endif
</div>
</section>
@endvolt

</x-auth::layouts.setup>
</div>
72 changes: 37 additions & 35 deletions resources/views/pages/auth/two-factor-challenge.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,47 +89,49 @@ public function submit_recovery_code(){
?>

<x-auth::layouts.app title="{{ config('devdojo.auth.language.twoFactorChallenge.page_title') }}">
@volt('auth.twofactorchallenge')
<x-auth::elements.container>

@if(!$recovery)
<x-auth::elements.heading
:text="($language->twoFactorChallenge->headline_auth ?? 'No Heading')"
:description="($language->twoFactorChallenge->subheadline_auth ?? 'No Description')"
:show_subheadline="($language->twoFactorChallenge->show_subheadline_auth ?? false)" />
@else
<x-auth::elements.heading
:text="($language->twoFactorChallenge->headline_recovery ?? 'No Heading')"
:description="($language->twoFactorChallenge->subheadline_recovery ?? 'No Description')"
:show_subheadline="($language->twoFactorChallenge->show_subheadline_recovery ?? false)" />
@endif

<form wire:submit="submit_auth_code" class="mt-5 space-y-5">
<div>
<x-auth::layouts.app title="{{ config('devdojo.auth.language.twoFactorChallenge.page_title') }}">
@volt('auth.twofactorchallenge')
<x-auth::elements.container>

@if(!$recovery)
<div class="relative">
<x-auth::elements.input label="Code" type="text" wire:model="auth_code" autofocus="true" id="auth-2fa-auth-code" required />
</div>
<x-auth::elements.heading
:text="($language->twoFactorChallenge->headline_auth ?? 'No Heading')"
:description="($language->twoFactorChallenge->subheadline_auth ?? 'No Description')"
:show_subheadline="($language->twoFactorChallenge->show_subheadline_auth ?? false)" />
@else
<div class="relative">
<x-auth::elements.input label="Recovery Code" type="text" wire:model="recovery_code" id="auth-2fa-recovery-code" required />
</div>
<x-auth::elements.heading
:text="($language->twoFactorChallenge->headline_recovery ?? 'No Heading')"
:description="($language->twoFactorChallenge->subheadline_recovery ?? 'No Description')"
:show_subheadline="($language->twoFactorChallenge->show_subheadline_recovery ?? false)" />
@endif

<x-auth::elements.button rounded="md" submit="true">Continue</x-auth::elements.button>
</form>
<form wire:submit="submit_auth_code" class="mt-5 space-y-5">

<div class="mt-5 space-x-0.5 text-sm leading-5 text-left" style="color:{{ config('devdojo.auth.appearance.color.text') }}">
<span class="opacity-[47%]">or you can </span>
<span class="font-medium underline opacity-60 cursor-pointer" wire:click="switchToRecovery" href="#_">
@if(!$recovery)
<span>login using a recovery code</span>
<div class="relative">
<x-auth::elements.input label="Code" type="text" wire:model="auth_code" autofocus="true" id="auth-2fa-auth-code" required />
</div>
@else
<span>login using an authentication code</span>
<div class="relative">
<x-auth::elements.input label="Recovery Code" type="text" wire:model="recovery_code" id="auth-2fa-recovery-code" required />
</div>
@endif
</span>
</div>
</x-auth::elements.container>
@endvolt
</x-auth::layouts.app>

<x-auth::elements.button rounded="md" submit="true">Continue</x-auth::elements.button>
</form>

<div class="mt-5 space-x-0.5 text-sm leading-5 text-left" style="color:{{ config('devdojo.auth.appearance.color.text') }}">
<span class="opacity-[47%]">or you can </span>
<span class="font-medium underline opacity-60 cursor-pointer" wire:click="switchToRecovery" href="#_">
@if(!$recovery)
<span>login using a recovery code</span>
@else
<span>login using an authentication code</span>
@endif
</span>
</div>
</x-auth::elements.container>
@endvolt
</x-auth::layouts.app>
</div>
4 changes: 2 additions & 2 deletions resources/views/pages/auth/verify.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function resend()
<div class="mt-5 text-sm leading-6 text-gray-700 dark:text-gray-400">
<p>Before proceeding, please check your email for a verification link. If you did not receive the email, <a wire:click="resend" class="text-gray-700 underline transition duration-150 ease-in-out cursor-pointer dark:text-gray-300 hover:text-gray-600 focus:outline-none focus:underline">click here to request another</a>.</p>
</div>



<div class="mt-2 space-x-0.5 text-sm leading-5 text-center text-gray-600 translate-y-4 dark:text-gray-400">
Expand All @@ -71,7 +71,7 @@ public function resend()
@csrf
</form>
</div>

</x-auth::elements.container>
@endvolt

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
use Livewire\Volt\Component;
name('user.two-factor-authentication');
//middleware(['auth', 'verified', 'password.confirm']);
//middleware(['auth', 'verified', 'password.confirm']);
middleware(['auth', 'verified']);
// middleware(['auth'])
new class extends Component
{
public $showingConfirmation = false;
public function mount(){
}
}
Expand Down Expand Up @@ -80,4 +80,4 @@ public function mount(){
</div>
@endvolt

</x-auth::layouts.empty>
</x-auth::layouts.empty>
24 changes: 24 additions & 0 deletions tests/Feature/AuthProvidersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

it('loads providers from configuration on mount', function () {
config()->set('devdojo.auth.providers', [
'google' => ['name' => 'Google', 'active' => true],
'facebook' => ['name' => 'Facebook', 'active' => false],
]);

Livewire::test('auth.setup.providers')
->assertSet('providers.google.active', true)
->assertSet('providers.facebook.active', false);
});

it('updates provider activation correctly and clears config cache', function () {
Livewire::test('auth.setup.providers')
->call('update', 'google', true)
->assertSet('providers.google.active', true);
assert(config('devdojo.auth.providers.google.active') === true);

Livewire::test('auth.setup.providers')
->call('update', 'google', false)
->assertSet('providers.google.active', false);
assert(config('devdojo.auth.providers.google.active') === false);
});

0 comments on commit e3e59cd

Please sign in to comment.