Skip to content

Commit

Permalink
Jans fido2 replace requested parties 9248 (#9586)
Browse files Browse the repository at this point in the history
* feat(jans-fido2): changed function type to be accessible and replaced requestParties name and domain with id and origins

Signed-off-by: imran-ishaq <imranishaq024@gmail.com>

* feat(jans-fido2): add test cases for createRpDomain function in AttestationServiceTest Class

Signed-off-by: imran-ishaq <imranishaq024@gmail.com>

---------

Signed-off-by: imran-ishaq <imranishaq024@gmail.com>
  • Loading branch information
imran-ishaq authored and moabu committed Nov 7, 2024
1 parent baea6b6 commit 41df57d
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 13 deletions.
16 changes: 8 additions & 8 deletions jans-cli-tui/cli_tui/plugins/020_fido/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def edit_requested_party(self, **kwargs: Any) -> None:
title = _("Enter Request Party Properties")
schema = self.app.cli_object.get_schema_from_reference('Fido2', '#/components/schemas/RequestedParty')
cur_data = kwargs.get('passed', ['', ''])
name_widget = self.app.getTitledText(_("Name"), name='name', value=cur_data[0], jans_help=self.app.get_help_from_schema(self.schema, 'name'), style='class:outh-scope-text')
domains_widget = self.app.getTitledText(_("Domains"), name='domains', value='\n'.join(cur_data[1].split(', ')), height=3, jans_help=self.app.get_help_from_schema(self.schema, 'domains'), style='class:dialog-titled-widget')
name_widget = self.app.getTitledText(_("ID"), name='id', value=cur_data[0], jans_help=self.app.get_help_from_schema(self.schema, 'id'), style='class:outh-scope-text')
domains_widget = self.app.getTitledText(_("Origins"), name='origins', value='\n'.join(cur_data[1].split(', ')), height=3, jans_help=self.app.get_help_from_schema(self.schema, 'origins'), style='class:dialog-titled-widget')

def add_request_party(dialog: Dialog) -> None:
name_ = name_widget.me.text
Expand Down Expand Up @@ -146,12 +146,12 @@ def create_widgets(self):
add_party_title = _("Add Party")

requested_parties_data = []
for rp in fido2_static_config.get('requestedParties', {}):
requested_parties_data.append([rp.get('name',''), ', '.join(rp.get('domains', []))])
for rp in fido2_static_config.get('rp', {}):
requested_parties_data.append([rp.get('id',''), ', '.join(rp.get('origins', []))])

self.requested_parties_container = JansVerticalNav(
myparent=self.app,
headers=['Name', 'Domains'],
headers=['id', 'origins'],
preferred_size=[30, 30],
data=requested_parties_data,
on_enter=self.edit_requested_party,
Expand All @@ -163,7 +163,7 @@ def create_widgets(self):
all_data=requested_parties_data,
underline_headings=False,
max_width=65,
jans_name='RequestedParties',
jans_name='rp',
max_height=False
)

Expand Down Expand Up @@ -288,9 +288,9 @@ def save_config(self) -> None:
fido2_config['personCustomObjectClassList'] = fido2_config['personCustomObjectClassList'].splitlines()
fido2_static['enabledFidoAlgorithms'] = fido2_static['enabledFidoAlgorithms'].splitlines()

fido2_static['requestedParties'] = []
fido2_static['rp'] = []
for name, domains in self.requested_parties_container.data:
fido2_static['requestedParties'].append({'name': name, 'domains': domains.splitlines()})
fido2_static['rp'].append({'id': name, 'origins': domains.splitlines()})

fido2_config['fido2Configuration'] = fido2_static

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ private Set<PublicKeyCredentialParameters> preparePublicKeyCredentialSelection()
return credentialParametersSets;
}

private RelyingParty createRpDomain(String documentDomain) {
public RelyingParty createRpDomain(String documentDomain) {
List<RequestedParty> requestedParties = appConfiguration.getFido2Configuration().getRequestedParties();

if ((requestedParties == null) || requestedParties.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package io.jans.fido2.service;

import io.jans.fido2.model.common.RelyingParty;
import io.jans.fido2.model.conf.AppConfiguration;
import io.jans.fido2.model.conf.Fido2Configuration;
import io.jans.fido2.model.conf.RequestedParty;
import io.jans.fido2.model.error.ErrorResponseFactory;
import io.jans.fido2.service.operation.AttestationService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;

import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class AttestationServiceTest {
@InjectMocks
private AttestationService attestationService;

@Mock
private AppConfiguration appConfiguration;

@Mock
private Logger log;

@Mock
private ErrorResponseFactory errorResponseFactory;


@Test
void createRpDomain_withValidIssuerAndDomain_createsRelyingPartySuccessfully() {
String rpDomain = "my.jans.server";
String rpId = "https://my.jans.server";
Fido2Configuration fido2Config = mock(Fido2Configuration.class);

when(appConfiguration.getIssuer()).thenReturn(rpId);
when(appConfiguration.getFido2Configuration()).thenReturn(fido2Config);

RelyingParty response = attestationService.createRpDomain(rpDomain);

assertNotNull(response);
assertEquals(rpDomain, response.getId());
assertEquals(rpId, response.getName());

verify(appConfiguration).getFido2Configuration();
verify(appConfiguration).getIssuer();
verifyNoInteractions(log, errorResponseFactory);
}

@Test
void createRpDomain_ifRequestedPartiesContainsMatchingDomain_success() {
String rpDomain = "my.jans.server";

Fido2Configuration fido2Config = mock(Fido2Configuration.class);

RequestedParty requestedParty = mock(RequestedParty.class);
String requestedPartyId = "https://my.jans.server";
String[] origins = {"my.jans.server",};
when(requestedParty.getOrigins()).thenReturn(Arrays.asList(origins));
when(requestedParty.getId()).thenReturn(requestedPartyId);

List<RequestedParty> requestedParties = List.of(requestedParty);
when(fido2Config.getRequestedParties()).thenReturn(requestedParties);

when(appConfiguration.getFido2Configuration()).thenReturn(fido2Config);

RelyingParty response = attestationService.createRpDomain(rpDomain);

assertNotNull(response);
assertEquals(rpDomain, response.getId());
assertEquals(requestedPartyId, response.getName());

verify(appConfiguration).getFido2Configuration();
verify(fido2Config).getRequestedParties();
verifyNoInteractions(log, errorResponseFactory);
}

}
4 changes: 2 additions & 2 deletions terraform-provider-jans/jans/fido2_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

type RequestedParties struct {
Name string `schema:"name" json:"name"`
Domains []string `schema:"domains" json:"domains"`
Id string `schema:"name" json:"name"`
Origins []string `schema:"domains" json:"domains"`
}

// Fido2Configuration represents the Fido2 configuration properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func TestResourceFido2Config_Mapping(t *testing.T) {
ServerMetadataFolder: "/etc/jans/conf/fido2/server_metadata",
RequestedParties: []jans.RequestedParties{
{
Name: "https://moabu-21f13b7c-9069-ad58-5685-852e6d236020.gluu.info",
Domains: []string{"moabu-21f13b7c-9069-ad58-5685-852e6d236020.gluu.info"},
Id: "https://moabu-21f13b7c-9069-ad58-5685-852e6d236020.gluu.info",
Origins: []string{"moabu-21f13b7c-9069-ad58-5685-852e6d236020.gluu.info"},
},
},
debugUserAutoEnrollment: false,
Expand Down

0 comments on commit 41df57d

Please sign in to comment.