-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/userinfo #273
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
Open
JasonRobertFrancis
wants to merge
54
commits into
main
Choose a base branch
from
feature/userinfo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/userinfo #273
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
bf2de8c
Update LdapService.cs
JasonRobertFrancis db98b3d
Adds models for UserInfo
JasonRobertFrancis 8c27012
Create UserInfoController.cs
JasonRobertFrancis 96e5784
Update UserInfo.cshtml
JasonRobertFrancis 22f6e30
Update .gitignore
JasonRobertFrancis 25e46f4
UserInfo first draft
JasonRobertFrancis 6a5fdfe
Updates Userinfo page
JasonRobertFrancis e11c276
Updates UserInfo page
JasonRobertFrancis 4223666
fix: clean up unused usings and resolve nullability warnings in tests
JasonRobertFrancis e89991c
Addresses code-review issues
JasonRobertFrancis f30712c
fix: resolve S1144 and S6580 Sonar warnings in IamApi
JasonRobertFrancis f416e35
fix: address PR reviews and linter suggestions
JasonRobertFrancis fed2a98
A few directory bug fixes (trailing slashes, race condition, loading …
JasonRobertFrancis 694ecd4
Fixes the results of the code-quality-bot's review
JasonRobertFrancis 99eebf8
fix(directory): resolve ReSharper code quality, XML doc, and unit tes…
JasonRobertFrancis 55a94ae
Refactors to remove clones (from adding the sidebar to the directory …
JasonRobertFrancis 4b023bf
Fixes ReSharper redundant constructor and property initializers
JasonRobertFrancis a65cc7c
Merges main changes in
JasonRobertFrancis f32f07f
Addresses linting issues
JasonRobertFrancis c674c9c
Addresses ReSharper issues
JasonRobertFrancis fb9579e
More ReSharper issues
JasonRobertFrancis cfde89d
ReSharper issues
JasonRobertFrancis cb89d91
parameterizes Instinct GraphQL query and updates system roles/permiss…
JasonRobertFrancis e8023d1
Fixes loading modal on directory when refreshing the page
JasonRobertFrancis 8cd6bd5
Fixes issue with potential null value
JasonRobertFrancis e29d9a9
feat(userinfo): translate getBase64Image.cfm to PublicPhotoController
JasonRobertFrancis 6a25271
Replaces .Where.FirstOrDefault to .FirstOrDefault
JasonRobertFrancis 5a8fdb3
Updates .gitignore
JasonRobertFrancis aa17db0
Updates links to User Photo and linting issues
JasonRobertFrancis 8563ac5
Merge remote-tracking branch 'origin/main' into feature/userinfo
JasonRobertFrancis ed417fa
Removes redundant user photo code and updates links
JasonRobertFrancis 0dbc8f4
Removing debugging (again)
JasonRobertFrancis 5141bfb
Updates address formatting on UserInfo page
JasonRobertFrancis cb6386a
Merge branch 'main' into feature/userinfo
JasonRobertFrancis 1d91ef2
Potential fix for pull request finding 'Generic catch clause'
JasonRobertFrancis 80a2709
Potential fix for pull request finding 'Generic catch clause'
JasonRobertFrancis 3542b90
Potential fix for pull request finding 'Generic catch clause'
JasonRobertFrancis 278c35b
Potential fix for pull request finding 'Missed opportunity to use Sel…
JasonRobertFrancis 05bd80a
Potential fix for pull request finding 'Missed opportunity to use Sel…
JasonRobertFrancis 646ac91
Potential fix for pull request finding 'Missed opportunity to use Sel…
JasonRobertFrancis bb30c9a
Potential fix for pull request finding 'Missed opportunity to use Sel…
JasonRobertFrancis 2c972d3
Potential fix for pull request finding 'Missed opportunity to use Where'
JasonRobertFrancis c5b9bb3
Potential fix for pull request finding 'Missed opportunity to use Where'
JasonRobertFrancis 1bb3159
Potential fix for pull request finding 'Missing Dispose call on local…
JasonRobertFrancis c77e4e8
fix(directory): resolve merge conflict and address LDAP exception han…
JasonRobertFrancis ef6cb56
Adds more specific exception handling
JasonRobertFrancis 820533e
Potential fix for pull request finding 'Missed opportunity to use Sel…
JasonRobertFrancis e39750e
Potential fix for pull request finding 'CodeQL / Generic catch clause'
JasonRobertFrancis f8b5862
Adds extra Student information
JasonRobertFrancis 6db5981
Fixes missing Student information
JasonRobertFrancis 59e44f6
Merge remote-tracking branch 'origin/main' into feature/userinfo
JasonRobertFrancis 4a2a8e1
Updates logging and removes generic catch statements
JasonRobertFrancis d2a8e4b
Addresses code review requests
JasonRobertFrancis c18d9c8
Addresses security review
JasonRobertFrancis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.Extensions.Caching.Memory; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.Logging; | ||
| using NSubstitute; | ||
| using System.Net; | ||
| using System.Text; | ||
| using Viper.Areas.Directory.Models; | ||
| using Viper.Areas.Directory.Services; | ||
| using Viper.Classes.SQLContext; | ||
| using Viper.Models.AAUD; | ||
| using Viper.Models.Courses; | ||
|
|
||
| namespace Viper.test.Services | ||
| { | ||
| public class UserInfoServiceTests | ||
| { | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public UserInfoServiceTests(ITestOutputHelper output) | ||
| { | ||
| _output = output; | ||
| } | ||
|
|
||
| private static DbContextOptions<TContext> CreateInMemoryOptions<TContext>() where TContext : DbContext | ||
| { | ||
| return new DbContextOptionsBuilder<TContext>() | ||
| .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) | ||
| .Options; | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task TestGetUserInfo_WithSyntheticData() | ||
| { | ||
| _output.WriteLine("[DEBUG] Starting TestGetUserInfo with fully synthetic data..."); | ||
|
|
||
| // 1. Arrange Config & Cache | ||
| var configData = new Dictionary<string, string?> | ||
| { | ||
| { "Instinct:ApiUrl", "https://synthetic.instinctvet.com/" }, | ||
| { "Credentials:InstinctApi", "synthetic-password" } | ||
| }; | ||
| var config = new ConfigurationBuilder() | ||
| .AddInMemoryCollection(configData) | ||
| .Build(); | ||
|
|
||
| var memoryCache = new MemoryCache(new MemoryCacheOptions()); | ||
|
|
||
| // 2. Mock HttpClientFactory | ||
| var mockHandler = new MockHttpMessageHandler(request => | ||
| { | ||
| var uri = request.RequestUri?.ToString() ?? ""; | ||
| if (uri.Contains("auth/token")) | ||
| { | ||
| return new HttpResponseMessage(HttpStatusCode.OK) | ||
| { | ||
| Content = new StringContent("{\"access_token\": \"synthetic-token\", \"expires_in\": 86400}", Encoding.UTF8, "application/json") | ||
| }; | ||
| } | ||
| if (uri.Contains("query=")) | ||
| { | ||
| var searchJson = @" | ||
| { | ||
| ""data"": { | ||
| ""searchUsers"": [ | ||
| { | ||
| ""id"": ""inst-synthetic-id"", | ||
| ""instinctId"": ""inst-synthetic-id"", | ||
| ""status"": ""Active"", | ||
| ""isActive"": true, | ||
| ""username"": ""jsmith"", | ||
| ""nameFirst"": ""John"", | ||
| ""nameLast"": ""Smith"", | ||
| ""roles"": [ | ||
| { ""label"": ""Staff"" } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| }"; | ||
| return new HttpResponseMessage(HttpStatusCode.OK) | ||
| { | ||
| Content = new StringContent(searchJson, Encoding.UTF8, "application/json") | ||
| }; | ||
| } | ||
| return new HttpResponseMessage(HttpStatusCode.NotFound); | ||
| }); | ||
|
|
||
| var httpClientFactory = Substitute.For<IHttpClientFactory>(); | ||
| httpClientFactory.CreateClient(Arg.Any<string>()).Returns(_ => new HttpClient(mockHandler)); | ||
|
|
||
| // 3. Setup DbContexts and Seed Synthetic Data | ||
| var aaudOptions = CreateInMemoryOptions<AAUDContext>(); | ||
| var coursesOptions = CreateInMemoryOptions<CoursesContext>(); | ||
|
|
||
| using (var aaudSetup = new AAUDContext(aaudOptions)) | ||
| { | ||
| var syntheticUser = new AaudUser | ||
| { | ||
| IamId = "99999999", | ||
| MothraId = "88888888", | ||
| MailId = "jsmith", | ||
| LoginId = "jsmith", | ||
| FirstName = "John", | ||
| LastName = "Smith", | ||
| DisplayFirstName = "John", | ||
| DisplayLastName = "Smith", | ||
| DisplayFullName = "John Smith", | ||
| Current = 1, | ||
| EmployeeId = "emp-999", | ||
| EmployeePKey = "pkey-999", | ||
| ClientId = "1" | ||
| }; | ||
| aaudSetup.AaudUsers.Add(syntheticUser); | ||
|
|
||
| aaudSetup.Employees.Add(new Employee | ||
| { | ||
| EmpPKey = "pkey-999", | ||
| EmpTermCode = "202610", | ||
| EmpPrimaryTitle = "Synthetic Analyst", | ||
| EmpSchoolDivision = "Synthetic Division", | ||
| EmpStatus = "A", | ||
| EmpHomeDept = "Synthetic Dept", | ||
| EmpClientid = "1", | ||
| EmpAltDeptCode = "", | ||
| EmpCbuc = "" | ||
| }); | ||
|
|
||
| await aaudSetup.SaveChangesAsync(TestContext.Current.CancellationToken); | ||
| } | ||
|
|
||
| using (var coursesSetup = new CoursesContext(coursesOptions)) | ||
| { | ||
| coursesSetup.Terminfos.Add(new Terminfo | ||
| { | ||
| TermCode = "202610", | ||
| TermCurrentTermMulti = true, | ||
| TermAcademicYear = "", | ||
| TermDesc = "", | ||
| TermCollCode = "01", | ||
| TermStartDate = DateTime.Today, | ||
| TermEndDate = DateTime.Today, | ||
| TermCurrentTerm = true, | ||
| TermTermType = "" | ||
| }); | ||
| await coursesSetup.SaveChangesAsync(TestContext.Current.CancellationToken); | ||
| } | ||
|
|
||
| using var aaud = new AAUDContext(aaudOptions); | ||
| using var raps = new RAPSContext(CreateInMemoryOptions<RAPSContext>()); | ||
| using var courses = new CoursesContext(coursesOptions); | ||
| using var loans = new EquipmentLoanContext(CreateInMemoryOptions<EquipmentLoanContext>()); | ||
| using var pps = new PPSContext(CreateInMemoryOptions<PPSContext>()); | ||
| using var idcards = new IDCardsContext(CreateInMemoryOptions<IDCardsContext>()); | ||
| using var keys = new KeysContext(CreateInMemoryOptions<KeysContext>()); | ||
| using var sis = new SISContext(CreateInMemoryOptions<SISContext>()); | ||
|
|
||
| var userInfoService = new UserInfoService(aaud, raps, courses, loans, pps, idcards, keys, sis, config, httpClientFactory, memoryCache, Substitute.For<ILogger<UserInfoService>>()); | ||
|
|
||
| // 4. Act | ||
| // Temporary HttpHelper configuration inside the test context | ||
| var mockEnv = Substitute.For<Microsoft.AspNetCore.Hosting.IWebHostEnvironment>(); | ||
| HttpHelper.Configure(memoryCache, config, mockEnv, null, null, null); | ||
|
|
||
| UserInfoResult? result; | ||
| try | ||
| { | ||
| result = await userInfoService.GetUserInfoAsync("99999999", "88888888"); | ||
| } | ||
| finally | ||
| { | ||
| HttpHelper.Configure(null, null, null!, null, null, null); | ||
| } | ||
|
|
||
| // 5. Assert | ||
| Assert.NotNull(result); | ||
| _output.WriteLine($"[DEBUG] Result IamId: {result.IamId}"); | ||
| _output.WriteLine($"[DEBUG] Result DisplayName: {result.DisplayFullName}"); | ||
| _output.WriteLine($"[DEBUG] Result InstinctId: {result.InstinctId}"); | ||
| _output.WriteLine($"[DEBUG] Result InstinctInfo.ErrorMessage: {result.InstinctInfo?.ErrorMessage}"); | ||
| _output.WriteLine($"[DEBUG] Result InstinctInfo.Valid: {result.InstinctInfo?.Valid}"); | ||
|
|
||
| Assert.Equal("99999999", result.IamId); | ||
| Assert.Equal("88888888", result.MothraId); | ||
| Assert.Equal("John Smith", result.DisplayFullName); | ||
| Assert.True(result.IsEmployee); | ||
| Assert.Equal("Synthetic Analyst", result.EmployeePrimaryTitle); | ||
| Assert.Equal("inst-synthetic-id", result.InstinctId); | ||
| Assert.Equal("jsmith", result.InstinctUsername); | ||
| } | ||
|
|
||
| private class MockHttpMessageHandler : HttpMessageHandler | ||
| { | ||
| private readonly Func<HttpRequestMessage, HttpResponseMessage> _handler; | ||
|
|
||
| public MockHttpMessageHandler(Func<HttpRequestMessage, HttpResponseMessage> handler) | ||
| { | ||
| _handler = handler; | ||
| } | ||
|
|
||
| protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
| { | ||
| return Task.FromResult(_handler(request)); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JasonRobertFrancis
shell: trueroutes these paths through cmd.exe on Windows, so a path with a space or&breaks.npx.cmdavoids it. Same at 273.