Skip to content

Commit

Permalink
Merge pull request #26 from digirati-co-uk/auth2-jan-2023
Browse files Browse the repository at this point in the history
Update Auth 2 for latest Jan 2023 specification work
  • Loading branch information
tomcrane committed Feb 14, 2023
2 parents b706e5a + 1fd947e commit 9fdfc0c
Show file tree
Hide file tree
Showing 18 changed files with 313 additions and 183 deletions.
2 changes: 1 addition & 1 deletion src/IIIF/IIIF.Tests/Auth/V2/ContentResourceWithAuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void ContentResource_Can_Have_Auth_Services()
var json = res.AsJson().Replace("\r\n", "\n");
const string expected = @"{
""id"": ""https://example.com/documents/my.pdf"",
""type"": ""Text""," + ReusableParts.ExpectedService + @"
""type"": ""Text""," + ReusableParts.ExpectedServiceAsArray + @"
}";
// Assert
json.Should().BeEquivalentTo(expected);
Expand Down
7 changes: 3 additions & 4 deletions src/IIIF/IIIF.Tests/Auth/V2/ImageServiceWithAuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ public void ImageService2_Can_Have_Auth_Services()

// Act
var json = imgService2.AsJson().Replace("\r\n", "\n");
const string expected = @"{
string expected = @"{
""@id"": ""https://example.com/image/service"",
""@type"": ""ImageService2""," + ReusableParts.ExpectedService + @"
}";
""@type"": ""ImageService2""," + ReusableParts.GetExpectedServiceAsSingle() + "}";
// Assert
json.Should().BeEquivalentTo(expected);
}
Expand All @@ -43,7 +42,7 @@ public void ImageService3_Can_Have_Auth_Services()
var json = imgService3.AsJson().Replace("\r\n", "\n");
const string expected = @"{
""id"": ""https://example.com/image/service"",
""type"": ""ImageService3""," + ReusableParts.ExpectedService + @"
""type"": ""ImageService3""," + ReusableParts.ExpectedServiceAsArray + @"
}";
// Assert
json.Should().BeEquivalentTo(expected);
Expand Down
150 changes: 112 additions & 38 deletions src/IIIF/IIIF.Tests/Auth/V2/ProbeServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using FluentAssertions;
using IIIF.Auth.V2;
using IIIF.ImageApi.V2;
Expand All @@ -12,21 +13,15 @@ namespace IIIF.Tests.Auth.V2
public class ProbeServiceTests
{
[Fact]
public void ProbeService_Can_Be_For_External_Resource()
public void ProbeService_Serialises()
{
// Arrange
var probe = new AuthProbeService2
{
Id = "https://example.org/resource1/probe",
Label = new LanguageMap("en", "A probe Service"),
For = new Image
{
Id = "https://example.org/resource1"
},
Location = new Image
{
Id = "https://example.org/resource1-open"
}
ErrorHeading = new LanguageMap("en", "errorHeading value"),
ErrorNote = new LanguageMap("en", "errorNote value")
};

// Act
Expand All @@ -35,14 +30,8 @@ public void ProbeService_Can_Be_For_External_Resource()
""id"": ""https://example.org/resource1/probe"",
""type"": ""AuthProbeService2"",
""label"": {""en"":[""A probe Service""]},
""for"": {
""id"": ""https://example.org/resource1"",
""type"": ""Image""
},
""location"": {
""id"": ""https://example.org/resource1-open"",
""type"": ""Image""
}
""errorHeading"": {""en"":[""errorHeading value""]},
""errorNote"": {""en"":[""errorNote value""]}
}";

// Assert
Expand All @@ -52,63 +41,148 @@ public void ProbeService_Can_Be_For_External_Resource()


[Fact]
public void ProbeService_Can_Be_For_ImageService2()
public void ProbeServiceResult_Can_Substitute_ImageService2()
{
// Arrange
var probe = new AuthProbeService2
var probe = new AuthProbeResult2
{
Id = "https://example.org/resource1/probe",
Label = new LanguageMap("en", "A probe Service"),
For = new ImageService2
Status = 401,
Substitute = new ImageService2
{
Id = "https://example.org/imageService2"
}
},
Heading = new LanguageMap("en", "heading value"),
Note = new LanguageMap("en", "note value")
};

// Act
var json = probe.AsJson().Replace("\r\n", "\n");
const string expected = @"{
""id"": ""https://example.org/resource1/probe"",
""type"": ""AuthProbeService2"",
""label"": {""en"":[""A probe Service""]},
""for"": {
""@context"": ""http://iiif.io/api/auth/2/context.json"",
""type"": ""AuthProbeResult2"",
""status"": 401,
""substitute"": {
""@id"": ""https://example.org/imageService2"",
""@type"": ""ImageService2""
}
},
""heading"": {""en"":[""heading value""]},
""note"": {""en"":[""note value""]}
}";

// Assert
json.Should().BeEquivalentTo(expected);
}

[Fact]
public void ProbeService_Can_Be_For_ImageService3()
public void ProbeService_Can_Substitute_ImageService3()
{
// Arrange
var probe = new AuthProbeService2
var probe = new AuthProbeResult2
{
Id = "https://example.org/resource1/probe",
Label = new LanguageMap("en", "A probe Service"),
For = new ImageService3
Status = 401,
Substitute = new ImageService3
{
Id = "https://example.org/imageService3"
}
},
Heading = new LanguageMap("en", "heading value"),
Note = new LanguageMap("en", "note value")
};

// Act
var json = probe.AsJson().Replace("\r\n", "\n");
const string expected = @"{
""id"": ""https://example.org/resource1/probe"",
""type"": ""AuthProbeService2"",
""label"": {""en"":[""A probe Service""]},
""for"": {
""@context"": ""http://iiif.io/api/auth/2/context.json"",
""type"": ""AuthProbeResult2"",
""status"": 401,
""substitute"": {
""id"": ""https://example.org/imageService3"",
""type"": ""ImageService3""
},
""heading"": {""en"":[""heading value""]},
""note"": {""en"":[""note value""]}
}";

// Assert
json.Should().BeEquivalentTo(expected);
}



[Fact]
public void ProbeService_Can_Provide_Location()
{
// Arrange
var probeResult2 = new AuthProbeResult2
{
Status = 200,
Location = new Video
{
Id = "https://example.org/video/12345/file.m3u8"
}
};

// Act
var json = probeResult2.AsJson().Replace("\r\n", "\n");
const string expected = @"{
""@context"": ""http://iiif.io/api/auth/2/context.json"",
""type"": ""AuthProbeResult2"",
""status"": 200,
""location"": {
""id"": ""https://example.org/video/12345/file.m3u8"",
""type"": ""Video""
}
}";

// Assert
json.Should().BeEquivalentTo(expected);
}


[Fact]
public void ProbeService_Can_Provide_AccessService()
{
// Arrange
var probe = new AuthProbeService2
{
Id = "https://example.org/resource1/probe",
Label = new LanguageMap("en", "A probe service"),
Service = new List<IService>()
{
new AuthAccessService2
{
Id = "https://example.com/auth/access",
Profile = AuthAccessService2.InteractiveProfile,
Label = new LanguageMap("en", "label value"),
Heading = new LanguageMap("en", "heading value"),
Note = new LanguageMap("en", "note value"),
ConfirmLabel = new LanguageMap("en", "confirmLabel value")
}
}
};

// Act
var json = probe.AsJson().Replace("\r\n", "\n");
const string expected = @"{
""id"": ""https://example.org/resource1/probe"",
""type"": ""AuthProbeService2"",
""label"": {""en"":[""A probe service""]},
""service"": [
{
""id"": ""https://example.com/auth/access"",
""type"": ""AuthAccessService2"",
""profile"": ""interactive"",
""label"": {""en"":[""label value""]},
""confirmlabel"": {""en"":[""confirmLabel value""]},
""heading"": {""en"":[""heading value""]},
""note"": {""en"":[""note value""]}
}
]
}";

// Assert
json.Should().BeEquivalentTo(expected);
}
}


}
91 changes: 51 additions & 40 deletions src/IIIF/IIIF.Tests/Auth/V2/ReusableParts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,74 @@

namespace IIIF.Tests.Auth.V2
{
public class ReusableParts
{
public const string ExpectedService = @"
""service"": [
{
public class ReusableParts
{
public const string ExpectedService = @"{
""id"": ""https://example.com/image/service/probe"",
""type"": ""AuthProbeService2""
},
{
""id"": ""https://example.com/login"",
""type"": ""AuthAccessService2"",
""profile"": ""interactive"",
""type"": ""AuthProbeService2"",
""service"": [
{
""id"": ""https://example.com/token"",
""type"": ""AuthTokenService2""
},
{
""id"": ""https://example.com/logout"",
""type"": ""AuthLogoutService2"",
""label"": {""en"":[""Logout from Example Institution""]}
""id"": ""https://example.com/login"",
""type"": ""AuthAccessService2"",
""profile"": ""interactive"",
""label"": {""en"":[""label property""]},
""service"": [
{
""id"": ""https://example.com/token"",
""type"": ""AuthAccessTokenService2""
},
{
""id"": ""https://example.com/logout"",
""type"": ""AuthLogoutService2"",
""label"": {""en"":[""Logout from Example Institution""]}
}
],
""confirmLabel"": {""en"":[""ConfirmLabel property""]},
""heading"": {""en"":[""heading property""]},
""note"": {""en"":[""note property""]}
}
],
""confirmLabel"": {""en"":[""ConfirmLabel property""]},
""header"": {""en"":[""Header property""]},
""description"": {""en"":[""Description property""]},
""failureHeader"": {""en"":[""FailureHeader property""]},
""failureDescription"": {""en"":[""FailureDescription property""]}
]
}
";

public const string ExpectedServiceAsArray = @"
""service"": [
" + ExpectedService + @" ]";

public static string GetExpectedServiceAsSingle()
{
return @"
""service"": " + ExpectedService.Replace("\n ", "\n");
}
]";

public static readonly List<IService> Auth2Services = new()
{
new AuthProbeService2
{
Id = "https://example.com/image/service/probe"
},
new AuthAccessService2
{
Id = "https://example.com/login",
Profile = AuthAccessService2.InteractiveProfile,
ConfirmLabel = new LanguageMap("en", "ConfirmLabel property"),
Header = new LanguageMap("en", "Header property"),
Description = new LanguageMap("en", "Description property"),
FailureHeader = new LanguageMap("en", "FailureHeader property"),
FailureDescription = new LanguageMap("en", "FailureDescription property"),
Id = "https://example.com/image/service/probe",
Service = new List<IService>
{
new AuthTokenService2
new AuthAccessService2
{
Id = "https://example.com/login",
Profile = AuthAccessService2.InteractiveProfile,
Label = new LanguageMap("en", "label property"),
ConfirmLabel = new LanguageMap("en", "confirmLabel property"),
Heading = new LanguageMap("en", "heading property"),
Note = new LanguageMap("en", "note property"),
Service = new List<IService>
{
new AuthAccessTokenService2
{
Id = "https://example.com/token"
},
new AuthLogoutService2
{
},
new AuthLogoutService2
{
Id = "https://example.com/logout",
Label = new LanguageMap("en", "Logout from Example Institution")
}
}
}
}
}
};
Expand Down
Loading

0 comments on commit 9fdfc0c

Please sign in to comment.