github.com/readium/readium-lcp-server@v0.0.0-20240101192032-6e95190e99f1/lsdserver/api/freshlicense_test.go (about) 1 // Copyright 2021 Readium Foundation. All rights reserved. 2 // Use of this source code is governed by a BSD-style license 3 // that can be found in the LICENSE file exposed on Github (readium) in the project repository. 4 5 package apilsd 6 7 import ( 8 "log" 9 "testing" 10 11 "github.com/readium/readium-lcp-server/config" 12 ) 13 14 // enter here an existing license id 15 var LicenseID string = "812bbfe8-9a57-4b14-b8f3-4e0fc6e841c0" 16 17 func TestGetUserData(t *testing.T) { 18 19 // enter here a valid URL 20 config.Config.LsdServer.UserDataUrl = "http://xx.xx.xx.xx:pppp/aaaaa/{license_id}/aaaa" 21 // enter here valid credentials 22 config.Config.CMSAccessAuth.Username = "xxxxx" 23 config.Config.CMSAccessAuth.Password = "xxxxx" 24 25 log.Println("username ", config.Config.CMSAccessAuth.Username) 26 27 userData, err := getUserData(LicenseID) 28 if err != nil { 29 t.Error(err.Error()) 30 t.FailNow() 31 } 32 33 if userData.Name == "" { 34 t.Error("Unexpected user name") 35 } 36 } 37 38 func TestInitPartialLicense(t *testing.T) { 39 40 userData := UserData{ 41 ID: "123-123-123", 42 Name: "John Doe", 43 Email: "jdoe@example.com", 44 Hint: "Good hint", 45 PassphraseHash: "faeb00ca518bea7cb11a7ef31f63183b489b1b6eadb792bec64a03b3f6ff80a8", 46 } 47 48 plic, err := initPartialLicense(LicenseID, userData) 49 50 if err != nil { 51 t.Error(err.Error()) 52 t.FailNow() 53 } 54 if plic.User.ID != userData.ID { 55 t.Error("Unexpected user ID") 56 } 57 58 if plic.Encryption.UserKey.Algorithm != Sha256_URL { 59 t.Error("Unexpected UserKey algorithm") 60 } 61 } 62 63 func TestFetchLicense(t *testing.T) { 64 65 // enter here a valid URL 66 config.Config.LcpServer.PublicBaseUrl = "http://xx.xx.xx.xx:pppp" 67 // enter here valid credentials 68 config.Config.LcpUpdateAuth.Username = "xxxx" 69 config.Config.LcpUpdateAuth.Password = "xxxx" 70 71 userData := UserData{ 72 ID: "123-123-123", 73 Name: "John Doe", 74 Email: "jdoe@example.com", 75 Hint: "Good hint", 76 PassphraseHash: "faeb00ca518bea7cb11sdf434b6183b489b1b6eadb792bec64a03b3f6ff80a8", 77 } 78 79 plic, _ := initPartialLicense(LicenseID, userData) 80 81 _, err := fetchLicense(plic) 82 if err != nil { 83 t.Error(err.Error()) 84 t.FailNow() 85 } 86 }