Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing tests of Identity Server module because of shared tempkey.rsa #3194

Closed
hikalkan opened this issue Mar 18, 2020 · 9 comments · Fixed by #3329
Closed

Failing tests of Identity Server module because of shared tempkey.rsa #3194

hikalkan opened this issue Mar 18, 2020 · 9 comments · Fixed by #3329

Comments

@hikalkan
Copy link
Member

System.IO.IOException : The process cannot access the file 'D:\Github\abp\modules\identityserver\test\Volo.Abp.IdentityServer.MongoDB.Tests\bin\Debug\netcoreapp3.1\tempkey.rsa' because it is being used by another process.

Is there any way to use an in-memory tempkey instead of a shared file?

@gterdem
Copy link
Contributor

gterdem commented Mar 23, 2020

image

How can I reproduce this?

@maliming
Copy link
Member

hi @gterdem

You can try using excel to open the tempkey.rsa file, or any editor that will lock the file. Then execute the dotnet test command in the identityserver module.

image

@maliming
Copy link
Member

During unit testing, files may be locked by other unit tests.

@gterdem
Copy link
Contributor

gterdem commented Mar 23, 2020

@maliming Thanks,
Because other parallel threads trying to access to file which is already in use. Ok, working on it.

@gterdem
Copy link
Contributor

gterdem commented Mar 24, 2020

Well, easier way is seems not create tempkey.rsa by

if (builderOptions.AddDeveloperSigningCredential)
{
   identityServerBuilder = identityServerBuilder.AddDeveloperSigningCredential(false);
}

However this may cause clients to re-signin when identityserver is restarted as stated in this issue
The only in-memory RSA key generation and persisting can be done with a distributed cache which is not reasonable.

@hikalkan @maliming the best way is to override/set identityServerBuilder.AddDeveloperSigningCredential(false) at test modules.
I tried on PreConfigureServices and ConfigureServices of AbpIdentityServerTestBaseModule however I got no luck.
Is it possible to override only signingCredential?

@maliming
Copy link
Member

hi @gterdem

Please refer to #1749 (comment)

@gterdem
Copy link
Contributor

gterdem commented Mar 24, 2020

thanks @maliming
I tried it;
Once AddIdentityServer method of AbpIdentityServerDomainModule kicks in, tempkey.rsa is already created and it is used for validation.

PreConfigure<IIdentityServerBuilder>(identityServerBuilder =>
{
    identityServerBuilder.AddDeveloperSigningCredential(false);
});

Doesn't seem to be overriding the validator keys.

@maliming
Copy link
Member

@gterdem Maybe this works.

public class AbpIdentityServerTestBaseModule : AbpModule
{
	public override void PreConfigureServices(ServiceConfigurationContext context)
	{
		PreConfigure<AbpIdentityServerBuilderOptions>(options =>
		{
			options.AddDeveloperSigningCredential = false;
		});
		
		PreConfigure<IIdentityServerBuilder>(identityServerBuilder =>
		{
			identityServerBuilder.AddDeveloperSigningCredential(persistKey: false, filename: Guid.NewGuid().ToString());
		});
	}
}

@gterdem
Copy link
Contributor

gterdem commented Mar 24, 2020

@maliming Cheers.

Works pretty fine. Sent PR about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment