@Override
    public Mono<List<ListedAuthProvider>> listAll() {
        return client.list(AuthProvider.class, provider ->
                    provider.getMetadata().getDeletionTimestamp() == null,
                defaultComparator()
            )
            .map(this::convertTo)
            .collectList()
            .flatMap(providers -> listMyConnections()
                .map(connection -> connection.getSpec().getRegistrationId())
                .collectList()
                .map(connectedNames -> providers.stream()
                    .peek(provider -> {
                        boolean isBound = connectedNames.contains(provider.getName());
                        provider.setIsBound(isBound);
                    })
                    .collect(Collectors.toList())
                )
                .defaultIfEmpty(providers)
            )
            .flatMap(providers -> fetchEnabledAuthProviders()
                .map(names -> providers.stream()
                    .peek(provider -> {
                        boolean enabled = names.contains(provider.getName());
                        provider.setEnabled(enabled);
                    })
                    .collect(Collectors.toList())
                )
                .defaultIfEmpty(providers)
            );
    }
@Test
    @WithMockUser(username = "admin")
    void listAll() {
        AuthProvider github = createAuthProvider("github");
        github.getSpec().setBindingUrl("fake-binding-url");

        AuthProvider gitlab = createAuthProvider("gitlab");
        gitlab.getSpec().setBindingUrl("fake-binding-url");

        AuthProvider gitee = createAuthProvider("gitee");

        when(client.list(eq(AuthProvider.class), any(), any()))
            .thenReturn(Flux.just(github, gitlab, gitee));
        when(client.list(eq(UserConnection.class), any(), any())).thenReturn(Flux.empty());

        ConfigMap configMap = new ConfigMap();
        configMap.setData(new HashMap<>());
        configMap.getData().put(SystemSetting.AuthProvider.GROUP, "{\"enabled\":[\"github\"]}");
        when(client.fetch(eq(ConfigMap.class), eq(SystemSetting.SYSTEM_CONFIG)))
            .thenReturn(Mono.just(configMap));

        authProviderService.listAll()
            .as(StepVerifier::create)
            .consumeNextWith(result -> {
                assertThat(result).hasSize(3);
                try {
                    JSONAssert.assertEquals("""
                            [{
                                "name": "github",
                                "displayName": "github",
                                "bindingUrl": "fake-binding-url",
                                "enabled": true,
                                "isBound": false,
                                "supportsBinding": false,
                                "privileged": false
                            }, {
                                "name": "gitlab",
                                "displayName": "gitlab",
                                "bindingUrl": "fake-binding-url",
                                "enabled": false,
                                "isBound": false,
                                "supportsBinding": false,
                                "privileged": false
                            },{
                                                        
                                "name": "gitee",
                                "displayName": "gitee",
                                "enabled": false,
                                "isBound": false,
                                "supportsBinding": false,
                                "privileged": false
                            }]
                            """,
                        JsonUtils.objectToJson(result),
                        true);
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
            })
            .verifyComplete();
    }